Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Running GUI application executable does not show the main window
QtWS25 Last Chance

[SOLVED] Running GUI application executable does not show the main window

Scheduled Pinned Locked Moved General and Desktop
qt 5.4.2c++qmlcompileapplicationgui
3 Posts 2 Posters 7.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnsmith
    wrote on last edited by johnsmith
    #1

    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.

    1 Reply Last reply
    0
    • Paul H.P Offline
      Paul H.P Offline
      Paul H.
      wrote on last edited by
      #2

      What if you add visible: true to main.qml?
      Paul

      J 1 Reply Last reply
      1
      • Paul H.P Paul H.

        What if you add visible: true to main.qml?
        Paul

        J Offline
        J Offline
        johnsmith
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved