Skip to content

Commit

Permalink
Fixes #37: Create main window for client application
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicx95 committed Apr 14, 2024
1 parent c8c221f commit e17376f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 69 deletions.
74 changes: 12 additions & 62 deletions communicator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,72 +1,22 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.16)

project(communicator VERSION 0.1 LANGUAGES CXX)
project(communicator VERSION 1.0 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt6 6.2 COMPONENTS Quick Gui REQUIRED)

qt_standard_project_setup(REQUIRES 6.5)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

add_compile_options(-Wall -Wextra -pedantic -Wno-unused-function -Werror)

set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(communicator
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET communicator APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(communicator SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(communicator
${PROJECT_SOURCES}
)
endif()
endif()

target_link_libraries(communicator PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.communicator)
endif()
set_target_properties(communicator PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
qt_add_executable(communicator
main.cpp
)

include(GNUInstallDirs)
install(TARGETS communicator
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
qt_add_qml_module(communicator
URI main
QML_FILES
main-window.qml
RESOURCES resources.qrc
)

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(communicator)
endif()
target_link_libraries(communicator PRIVATE Qt6::Gui Qt6::Quick)
35 changes: 35 additions & 0 deletions communicator/main-window.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

ApplicationWindow {
visible: true
width: 600
height: 400
minimumWidth: 400
minimumHeight: 300
title: "Simple Text Communicator"
color: "#f0f0f0"

ColumnLayout {
anchors.fill: parent
spacing: 10

RowLayout {
width: parent.width
Layout.alignment: Qt.AlignHCenter
Button {
text: "Login"
Layout.alignment: Qt.AlignRight
onClicked: {
}
}
Button {
text: "Register"
Layout.alignment: Qt.AlignRight
onClicked: {
}
}
}
}
}
21 changes: 14 additions & 7 deletions communicator/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include <QApplication>

#include "mainwindow.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

int main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;

const QUrl url(QStringLiteral("qrc:/qt/qml/main/main-window.qml"));
engine.load(url);
if (engine.rootObjects().isEmpty())
{
return -1;
}
return app.exec();
}
5 changes: 5 additions & 0 deletions communicator/resources.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/main">
<file>main-window.qml</file>
</qresource>
</RCC>

0 comments on commit e17376f

Please sign in to comment.