Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can't get menu bar in Qt Quick Components, using C++ and QQmlApplicationEngine
QtWS25 Last Chance

Can't get menu bar in Qt Quick Components, using C++ and QQmlApplicationEngine

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.9k 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.
  • T Offline
    T Offline
    Tory Gaurnier
    wrote on last edited by
    #1

    Now that Ubuntu finally has Qt 5.2, I'm playing with Qt Quick Components, and right now I'm having issues trying to get the menu bar to show, when I try to implement the menubar I get this message:

    appmenu-qt: handleReparent 128 The given QWindow has no QMenuBar assigned

    This is how I'm launching my Qml from C++:
    @
    // First initialize Qt Application
    QGuiApplication app(argc, argv);
    // Second initialize config singleton
    Config::init();
    QQmlApplicationEngine engine;
    engine.load(QUrl::fromLocalFile(config->getBinDir() + "/qml/main.qml"));
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow mainWindow = qobject_cast<QQuickWindow>(topLevel);

    mainWindow->show();
    return app.exec();
    @

    And this is the Qml I have so far:
    @
    import QtQuick.Controls 1.1
    import QtQuick.Dialogs 1.1
    import QtQuick 2.2

    ApplicationWindow {
    visible: true
    width: 640
    height: 480
    minimumWidth: 400
    minimumHeight: 300

    title: "MyApp"

    // Actions for menu items
    Item {
    id: globalActions

    Action {
    id: quitAction
    text: i18n.tr("Quit");
    onTriggered: Qt.quit();
    }

    Action {
    id: prefAction
    text: i18n.tr("Preferences");
    //onTriggered: TODO - LAUNCH PREFERENCES
    }

    Action {
    id: aboutAction
    text: i18n.tr("About");
    //onTriggered: TODO - LAUNCH ABOUT
    }
    }

    MessageDialog {
    id: aboutBox
    title: "MyApp"
    text: "This is a test app for Qt Quick Components"
    icon: StandardIcon.Information
    }

    menuBar: MenuBar {
    Menu {
    title: "&File"
    MenuItem { action: quitAction }
    }
    Menu {
    title: "&Edit"
    MenuItem { action: prefAction }
    }
    Menu {
    title: "&Help"
    MenuItem { action: aboutAction }
    }
    }
    }
    @

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vidar
      wrote on last edited by
      #2

      Can you check, whether your window is really a window?

      @ QQuickWindow * window = qobject_cast<QQuickWindow *>(topLevel);
      if ( !window ) {
      qWarning("Error: Your root item has to be a Window.");
      return -1;
      }@

      My code is very similar to yours, except for the Config::init command. I previously had trouble with doing init stuff in an order that the QT framework somehow did not like.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tory Gaurnier
        wrote on last edited by
        #3

        Thanks for the reply, I added if(!mainWindow), but it evaluates to true, so it is really a window. For arguments sake I commented out the config->init, and it didn't make a difference.

        If you have code that works, could you post just that portion of the code?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tory Gaurnier
          wrote on last edited by
          #4

          I should also note that the window itself does show, and any components (such as a text area) I put in it will show as well, just not the menu bar.

          In case it makes a difference I'm on Ubuntu 14.04

          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