[SOLVED] How to show QMenu with QML 2.0 in Qt 5
-
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!
-
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 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!
-
I just added a new ApplicationTemplate example to demonstrate how you can make a main window at the moment.
-
[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?
-
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 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.