CMAKE can't add qml file
-
Hi, when using cmake I cannot add additional qml files. Here is my code. It works with qmake.
main.qml
import QtQuick import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 ApplicationWindow { property string rootTitle: "Testing" property string firstPageTitle: "First page" property string secondPageTitle: "Second Page" property string thirdPageTitle: "Third page" id: root width: 480 height: 640 visible: true title: rootTitle header: ToolBar { RowLayout { anchors.fill: parent ToolButton { id: title text: rootTitle Layout.fillWidth: true onClicked: { menu.open() } } } } Menu { id: menu width: root.width height: root.height font.pointSize: 15 MenuItem { // FIRST PAGE height: root.height / 3 Rectangle { height: parent.height width: parent.width color: "red" opacity: 0.8 Text { font.pointSize: 15 text: firstPageTitle anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter } } onClicked: { title.text = firstPageTitle stack.push(firstpage) } } MenuItem { // SECOND PAGE height: root.height / 3 Rectangle { height: parent.height width: parent.width color: "blue" opacity: 0.8 Text { font.pointSize: 15 text: secondPageTitle anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter } } onClicked: { title.text = secondPageTitle stack.push(secondpage) } } MenuItem { // THIRD PAGE height: root.height / 3 Rectangle { height: parent.height width: parent.width color: "orange" opacity: 0.8 Text { font.pointSize: 15 text: thirdPageTitle anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter } } onClicked: { tittle.text = thirdPageTitle stack.push(thirdpage) } } } StackView { id: stack anchors.fill: parent } Component { id: firstpage Loader { source: "qrc:/firstpage.qml" } } Component { id: secondpage Loader { source: "qrc:/secondpage.qml" } } Component { id: thirdpage Loader { source: "qrc:/thirdpage.qml" } } Component.onCompleted: { menu.open() } }
firstpage.qml
import QtQuick import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 Item { Rectangle { anchors.fill: parent color: "blue" } }
CMakeLists.txt
cmake_minimum_required(VERSION 3.16) project(testing VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.2 COMPONENTS Quick QuickControls2 REQUIRED) qt_add_executable(apptesting main.cpp res.qrc ) qt_add_qml_module(apptesting URI testing VERSION 1.0 QML_FILES main.qml ) set_target_properties(apptesting PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(apptesting PRIVATE Qt6::Quick Qt6::QuickControls2) install(TARGETS apptesting BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})