error: ninja: build stopped: subcommand failed.
Unsolved
QML and Qt Quick
-
This is my example (Qt 6.4.3)
main.qml
:import QtQuick DocumentQML { visible: true }
DocumentQML.qml
:import QtQuick import QtQuick.Controls import Qt.labs.platform as NativeDialog ApplicationWindow { id: root title: (fileName.length === 0 ? "Document" : filename) + isDirty ? "*" : "" width: 800 height: 600 property bool isDirty: true property string fileName property bool tryingToClose: false menuBar: MenuBar { Menu { title: qsTr("&File") MenuItem { text: qsTr("&New") icon.name: "document-new" onTriggered: root.newDocument() } MenuSeparator {} MenuItem { text: qsTr("&Open") icon.name: "document-open" onTriggered: openDocument() } MenuItem { text: qsTr("&Save") icon.name: "document-save" onTriggered: saveDocument() } MenuItem { text: qsTr("Save &As...") icon.name: "document-save-as" onTriggered: saveAsDocument() } } } function createNewDocument() { var component = Qt.createComponent("DocumentWindow.qml"); var window = component.createObject(); return window; } function NewDocument() { var window = createNewDocument(); window.show(); } function openDocument() { openDialog.open(); } function saveAsDocument() { saveAsDialog.open(); } function saveDocument() { if(fileName.length === 0) root.saveAsDocument(); else { // Save document here console.log("Saving document") root.isDirty = false; if(root.tryingToClose) root.close(); } } NativeDialog.FileDialog { id: openDialog title: "Open" folder: NativeDialog.StandardButton.writableLocation( NativeDialog.StandardPaths.DocumentsLocation) onAccepted: { var window = root.createNewDocument(); window.fileName = openDialog.file(); window.show(); } } NativeDialog.FileDialog { id:saveAsDialog title: "Save as" folder: NativeDialog.StandardPaths.writableLocation( NativeDialog.StandardPaths.DocumentsLocation) onAccepted : { root.fileName = saveAsDialog.file saveDocument(); } onRejected: root.tryingToClose = false; } onClosing: if(root.isDirty) { closeWarningDialog.open(); close.accepted = false; } NativeDialog.MessageDialog { id: closeWarningDialog title: "Cloasing document" text: "You have unsaved changes. Do you want to save your changes?" buttons: NativeDialog.MessageDialog.Yes | NativeDialog.MessageDialog.No | NativeDialog.MessageDialog.Cancel onYesClicked: { // Attempt to save the document root.tryingToClose = true root.saveDocument(); } onNoClicked: { // Close the window root.isDirty = false root.close() } onReject: {/* do nothing */ } } }
CMakeLists.txt
:cmake_minimum_required(VERSION 3.16) project(QML_3 VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.5 REQUIRED COMPONENTS Quick) qt_standard_project_setup(REQUIRES 6.5) qt_add_executable(appQML_3 main.cpp ) qt_add_qml_module(appQML_3 URI QML_3 VERSION 1.0 QML_FILES Main.qml DocumentQML.qml ) set_target_properties(appQML_3 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(appQML_3 PRIVATE Qt6::Quick ) install(TARGETS appQML_3 BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
When run, I get this error:
error: ninja: build stopped: subcommand failed.