[SOLVED]QSystemTrayIcon for console applications
-
Hi all,
Can I use QSystemTrayIcon for console applications?
PS
I tried to test it by using the following snippet but I got a runtime error:---main.cpp
@
#include <QtCore/QCoreApplication>
#include <QSystemTrayIcon>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);QSystemTrayIcon *iconTray = new QSystemTrayIcon(QIcon(":/pixmap/res/icon.png")); iconTray->show(); return a.exec();
}
@---test.pro
@
QT += coreQT += gui
TARGET = TRAY-APP
CONFIG += console
CONFIG += app_bundleTEMPLATE = app
SOURCES += main.cpp
RESOURCES +=
res.qrc
@---runtime error
@
QWidget: Cannot create a QWidget when no GUI is being usedThis application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
@[EDIT: fixed code formatting, Volker]
-
You can build a console application in the sense that there is no main window or GUI or the like. But as you instantiate a GUI element - the QSystemTrayIcon - your application needs to initialize the graphics system. Therefore your need a QApplication instead of a QCoreApplication. If you change that, the code should work.
-
Thanks a lot... it's working fine