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. [SOLVED] How to show QMenu with QML 2.0 in Qt 5
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to show QMenu with QML 2.0 in Qt 5

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 5.1k Views 1 Watching
  • 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.
  • shavS Offline
    shavS Offline
    shav
    wrote on last edited by
    #1

    Hi,

    I have a problem with System menu like Main menu which created by code:
    @
    //Menu "File"
    QMenu* file = new QMenu("File");
    QAction* openFile = file->addAction("Open...");
    connect(openFile, SIGNAL(triggered()), SLOT(showOpenFileDialog()));

    //Menu "Help"
    QMenu* help = new QMenu("Help");
    QAction* aboutDialog = help->addAction("About");
    connect(aboutDialog, SIGNAL(triggered()), SLOT(showAboutDialog()));
    
    //Menu "Preferences"
    QMenu* preferences = new QMenu("Preferences");
    QAction* settings = preferences->addAction("Settings");
    connect(settings, SIGNAL(triggered()), SLOT(showSettingsDialog()));
    
    //Menu "Simulator"
    QMenu* sims = new QMenu("Simulators");
    QAction* sim_iPhone4S = sims->addAction("iPhone 4S");
    connect(sim_iPhone4S, SIGNAL(triggered()), SLOT(showSimulator()));
    sims->addSeparator();
    sim_imageBrodcast = sims->addAction("Enabled Image Brodcast");
    sim_imageBrodcast->setCheckable(true);
    connect(sim_imageBrodcast, SIGNAL(triggered(bool)), SLOT(onImageBrodcastEnabled(bool)));
    
    
    //Create a main menu
    QMenuBar* menu = new QMenuBar();
    menu->addMenu(file);
    menu->addMenu(help);
    menu->addMenu(preferences);
    menu->addMenu(sims);
    
    //Add a main menu bar.
    setMenuBar(menu);
    

    @

    This code I use in QMainWindow application based. This code work for me in Qt 4.8.x and QML 1.1. I created a subclass from QMainWindow and added a QML to it like a centerWidget using method:
    @
    setCentralWidget();
    @

    This work in Qt 4.8.x but I can't use it in Qt 5.0 because QQuickView class and all his subclass can't added like central widget because it's not a widget. So, my question is: How I can show standard main menu in my application which using QML 2.0 and Qt 5.0?

    P.S. I known about QML Desktop Components projects but I can't compile any projects with this plugin. I wrote about my problem in this "post":http://qt-project.org/forums/viewthread/23096/P15/#107961. Also, this project doesn't released yet. So, I think it's have a problem with work in real projects.

    Thanks for the any help!

    Mac OS and iOS Developer

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      To use QMainWindow with qt quick in Qt 5.0, you still have to use the QQuick 1 compatibility classes. There is no offical way to mix widgets and QtQuick 2.0 yet.

      In Qt 5.1 the plan is to have a QtQuickWidget you can insert into QMainWindow in a similar fashion to what you are doing, so perhaps you should wait with porting the application until then.

      Edit: https://codereview.qt-project.org/#change,41539 (WIP windowcontainer)

      1 Reply Last reply
      0
      • shavS Offline
        shavS Offline
        shav
        wrote on last edited by
        #3

        [quote author="Jens" date="1357158176"]To use QMainWindow with qt quick in Qt 5.0, you still have to use the QQuick 1 compatibility classes. There is no offical way to mix widgets and QtQuick 2.0 yet.

        In Qt 5.1 the plan is to have a QtQuickWidget you can insert into QMainWindow in a similar fashion to what you are doing, so perhaps you should wait with porting the application until then.

        Edit: https://codereview.qt-project.org/#change,41539 (WIP windowcontainer)[/quote]

        Thanks for the reply and information! But I think I can use the QML Desktop Components for my projects if I found the way to using it without "Qt Quick 2 UI" template.

        If you known any ways to use QML Desktop Components in template like "Qt Quick 2 Applciations (Built-in Elements)", please tell me about it, thanks!

        Mac OS and iOS Developer

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jens
          wrote on last edited by
          #4

          I just added a new ApplicationTemplate example to demonstrate how you can make a main window at the moment.

          1 Reply Last reply
          0
          • shavS Offline
            shavS Offline
            shav
            wrote on last edited by
            #5

            [quote author="Jens" date="1357240573"]I just added a new ApplicationTemplate example to demonstrate how you can make a main window at the moment.[/quote]

            Thanks! It's works for me now!

            By the way, how I can use QML Desktop Components in release version of my Application. For example, I want to use it in another PC where QML Desktop component not installed. Must I copied all modules to application's folder?

            Mac OS and iOS Developer

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jens
              wrote on last edited by
              #6

              You can keep a ship a copy of the QtDesktop dir with your application and set the qml import path in your application. This is done by using engine.addImportPath(...) for instance or pass -I $PATH as a command line argument to the application.

              1 Reply Last reply
              0
              • shavS Offline
                shavS Offline
                shav
                wrote on last edited by
                #7

                [quote author="Jens" date="1357251384"]You can keep a ship a copy of the QtDesktop dir with your application and set the qml import path in your application. This is done by using engine.addImportPath(...) for instance or pass -I $PATH as a command line argument to the application. [/quote]

                Thanks I will check it.

                Mac OS and iOS Developer

                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