qml - Is it possible to implement SystemTrayIcon functionality in Qt Quick application -


i writing qtquick desktop application. use both c++ (for functionality) , qml (for ui) in it. use qquickview show interface written in qml.

i want application reside in system tray when minimised.

i mean functionality similar example. http://qt-project.org/doc/qt-4.8/desktop-systray.html . trying implement feature not find way in qt quick application.

here main.cpp code:

#include <qguiapplication> #include <qqmlengine> #include <qqmlcontext> #include <qqmlfileselector> #include <qquickview> #include "myapp.h"  int main(int argc, char* argv[]) {     qguiapplication app(argc,argv);     app.setapplicationname(qfileinfo(app.applicationfilepath()).basename());     qdir::setcurrent(qapp->applicationdirpath());      myapp myappobject;      qquickview view;      view.connect(view.engine(), signal(quit()), &app, slot(quit()));     view.rootcontext()->setcontextproperty("myappobject", &myappobject);     new qqmlfileselector(view.engine(), &view);      view.setsource(qurl("qrc:///myapp.qml"));      view.setresizemode(qquickview::sizerootobjecttoview);        view.show();      return app.exec(); } 

please providing hint/pointers this.

thanks.

i facing same challenge today , ended using following solution within main(). works great me when using qt 5.3. should of course implement better way check whether first root object application window object or not.

#include <qapplication> #include <qqmlapplicationengine> #include <qmessagebox> #include <qaction> #include <qmenu> #include <qsystemtrayicon>  int main(int argc, char *argv[]) {     qapplication app(argc, argv);      if (!qsystemtrayicon::issystemtrayavailable()) {         qmessagebox::critical(0, qobject::tr("systray"),                                  qobject::tr("i couldn't detect system tray "                                              "on system."));         return 1;     }     qapplication::setquitonlastwindowclosed(false);      qqmlapplicationengine engine;     engine.load(qurl(qstringliteral("qrc:///main.qml")));      qobject *root = 0;     if (engine.rootobjects().size() > 0)     {         root = engine.rootobjects().at(0);          qaction *minimizeaction = new qaction(qobject::tr("mi&nimize"), root);         root->connect(minimizeaction, signal(triggered()), root, slot(hide()));         qaction *maximizeaction = new qaction(qobject::tr("ma&ximize"), root);         root->connect(maximizeaction, signal(triggered()), root, slot(showmaximized()));         qaction *restoreaction = new qaction(qobject::tr("&restore"), root);         root->connect(restoreaction, signal(triggered()), root, slot(shownormal()));         qaction *quitaction = new qaction(qobject::tr("&quit"), root);         root->connect(quitaction, signal(triggered()), qapp, slot(quit()));          qmenu *trayiconmenu = new qmenu();         trayiconmenu->addaction(minimizeaction);         trayiconmenu->addaction(maximizeaction);         trayiconmenu->addaction(restoreaction);         trayiconmenu->addseparator();         trayiconmenu->addaction(quitaction);          qsystemtrayicon *trayicon = new qsystemtrayicon(root);         trayicon->setcontextmenu(trayiconmenu);         trayicon->seticon(qicon(":/resources/datagnanlogocolor.png"));         trayicon->show();     }      return app.exec(); } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -