initial setup
This commit is contained in:
commit
4da9a275a9
72
CMakeLists.txt
Normal file
72
CMakeLists.txt
Normal file
@ -0,0 +1,72 @@
|
||||
cmake_minimum_required(VERSION 3.21.1)
|
||||
|
||||
project(megpie
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.6 REQUIRED COMPONENTS Core Gui Qml Quick QuickControls2 QuickLayouts)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_policy(SET QTP0001 NEW)
|
||||
|
||||
if(NOT EMSCRIPTEN AND CMAKE_TOOLCHAIN_FILE MATCHES ".*Emscripten\.cmake$")
|
||||
set(EMSCRIPTEN TRUE)
|
||||
endif()
|
||||
|
||||
qt_add_executable(megpie
|
||||
root.cpp
|
||||
)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif ()
|
||||
message("Build type: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||
set(CMAKE_CXX_FLAGS "-gsource-map")
|
||||
else()
|
||||
target_compile_options(megpie PRIVATE -Oz -g0)
|
||||
target_link_options(megpie PRIVATE -0z -g0 --closure 1)
|
||||
endif()
|
||||
message("building for emscripten")
|
||||
target_sources(megpie PRIVATE main_web.cpp)
|
||||
else()
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||
else()
|
||||
target_compile_options(megpie PRIVATE -O3)
|
||||
endif()
|
||||
message("building for desktop")
|
||||
target_sources(megpie PRIVATE main.cpp)
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||
else()
|
||||
target_compile_options(megpie PRIVATE -flto)
|
||||
target_link_options(megpie PRIVATE -flto)
|
||||
endif()
|
||||
|
||||
add_subdirectory(qml)
|
||||
|
||||
target_link_libraries(megpie PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Qml
|
||||
Qt6::Quick
|
||||
Qt6::QuickControls2
|
||||
Qt6::QuickLayouts
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS megpie
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
31
main.cpp
Normal file
31
main.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
#include "root.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Root app(argc, argv);
|
||||
|
||||
std::cout << "Starting" << std::endl;
|
||||
QQmlApplicationEngine engine;
|
||||
const QUrl url(u"qrc:qml/main.qml"_qs);
|
||||
QObject::connect(
|
||||
&engine, &QQmlApplicationEngine::objectCreated, &app,
|
||||
[&url](QObject* obj, const QUrl& objUrl) {
|
||||
if (!obj && url == objUrl)
|
||||
QCoreApplication::exit(-2);
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
|
||||
engine.load(url);
|
||||
if (engine.rootObjects().isEmpty())
|
||||
return -1;
|
||||
|
||||
int result;
|
||||
try {
|
||||
result = app.exec();
|
||||
} catch (...) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
25
main_web.cpp
Normal file
25
main_web.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
#include "root.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Root* app = new Root(argc, argv);
|
||||
|
||||
std::cout << "Starting" << std::endl;
|
||||
QQmlApplicationEngine* engine = new QQmlApplicationEngine();
|
||||
const QUrl url(u"qrc:qml/main.qml"_qs);
|
||||
QObject::connect(
|
||||
engine, &QQmlApplicationEngine::objectCreated, app,
|
||||
[url](QObject* obj, const QUrl& objUrl) {
|
||||
if (!obj && url == objUrl)
|
||||
QCoreApplication::exit(-2);
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
|
||||
engine->load(url);
|
||||
if (engine->rootObjects().isEmpty())
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
11
qml/CMakeLists.txt
Normal file
11
qml/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
qt_add_qml_module(megpieQml
|
||||
URI "qml"
|
||||
VERSION 1.0
|
||||
STATIC
|
||||
RESOURCE_PREFIX /
|
||||
NO_PLUGIN
|
||||
QML_FILES
|
||||
main.qml
|
||||
)
|
||||
|
||||
target_link_libraries(megpie PRIVATE megpieQml)
|
59
qml/main.qml
Normal file
59
qml/main.qml
Normal file
@ -0,0 +1,59 @@
|
||||
import QtQuick
|
||||
import QtQuick.Window
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Window {
|
||||
property int counter: 0
|
||||
|
||||
id: window
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Hello World")
|
||||
|
||||
Rectangle {
|
||||
id: page
|
||||
anchors.fill: parent
|
||||
anchors.centerIn: parent
|
||||
color: increment.down ? "blue" : decrement.down ? "red" : "lightgrey"
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: 100
|
||||
target: page
|
||||
easing.type: Easing.InOutQuad
|
||||
}
|
||||
}
|
||||
|
||||
GridLayout {
|
||||
anchors.centerIn: parent
|
||||
columns: 2
|
||||
|
||||
Text {
|
||||
Layout.columnSpan: 2
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: qsTr("Hello World")
|
||||
font.pointSize: 24; font.bold: true
|
||||
}
|
||||
|
||||
Button {
|
||||
id: increment
|
||||
text: "Increment"
|
||||
onClicked: window.counter++
|
||||
}
|
||||
|
||||
Button {
|
||||
id: decrement
|
||||
text: "Decrement"
|
||||
onClicked: window.counter--
|
||||
}
|
||||
|
||||
Text {
|
||||
Layout.columnSpan: 2
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: "The value is " + window.counter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
root.cpp
Normal file
27
root.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "root.h"
|
||||
|
||||
Root::Root(int& argc, char* argv[]) :
|
||||
QGuiApplication(argc, argv)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Root::~Root() {
|
||||
|
||||
}
|
||||
|
||||
bool Root::notify(QObject* receiver, QEvent* e) {
|
||||
try {
|
||||
return QGuiApplication::notify(receiver, e);
|
||||
} catch (const std::exception& e) {
|
||||
std::cout << "Caught an exception, error message:\n" << e.what() << std::endl;
|
||||
} catch (const int& e) {
|
||||
std::cout << "Caught int exception: " << e << std::endl;
|
||||
} catch (...) {
|
||||
std::cout << "Caught an exception" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Squawk is quiting..." << std::endl;
|
||||
exit(1);
|
||||
return false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user