[SOLVED] Running GUI application executable does not show the main window
-
I am trying to learn C++, Qt and QML by writing a simple app, but I am having trouble running the executable after I compile it. This is the code in main.cpp
#include <QtGui/QGuiApplication> #include <QtQml/QQmlApplicationEngine> #include <QtCore/QUrl> #include <QtQml/QQmlContext> #include <aboutappdialog.h> #include <aboutqtdialog.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; AboutAppDialog aboutApp; AboutQtDialog aboutQt; engine.rootContext()->setContextProperty("aboutApp", &aboutApp); engine.rootContext()->setContextProperty("aboutQt", &aboutQt); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
And this is the code of main.qml:
ApplicationWindow { id: mainWindow title: "MyApp" minimumHeight: 420 minimumWidth: 420 visibility: Window.AutomaticVisibility menuBar: MenuBar { Menu { title: qsTr("App") MenuItem { text: qsTr("New") shortcut: "Ctrl+N" onTriggered: Qt.quit() // change this } MenuItem { text: qsTr("Quit") shortcut: "Alt+F4" onTriggered: Qt.quit() } } Menu { title: qsTr("Tools") MenuItem { text: qsTr("Options") shortcut: "Ctrl+O" onTriggered: Qt.quit() //change this } } Menu { title: qsTr("About") MenuItem { text: qsTr("About Quick Tac Toe") onTriggered: { aboutApp = new AboutAppDialog(mainWindow); aboutApp.aboutApp(mainWindow); } } MenuItem { text: qsTr("About Qt") onTriggered: { aboutQt = new AboutQtDialog(mainWindow); aboutQt.aboutQt(mainWindow); } } } } }
When I run the executable from the command line after building it, all I get is the following message: using qt5ct plugin
When I run qmlscene main.qml it does show the GUI as expected, but upon clicking the menu items for the "About" dialogs defined in C++, I get errors like this: ReferenceError: AboutAppDialog is not defined
So the question is simple: what am I doing wrong. Thanks in advance.
-
@Paul-H. D'oh! Why, of course, how silly of me. visibility: Window.AutomaticVisibility does NOT automatically do visible: true.
Truly a case of needing to ask someone else to realize you're making a rookie mistake. Thanks for your help, Paul.