Application doesn't find Qt libraries during compilation process
-
I want to build hide console application (not visible components) but system tray icon. My application should use QSerialPort, networking and some else features. So I configure my pro file as follows:
QT -= gui CONFIG += c++11 console serialport network CONFIG -= app_bundle SOURCES += \ main.cpp RESOURCES += \ resources.qrc
The application won't build because tons of errors:
undefined reference to `_imp___ZN11QSerialPortC1EP7QObject' undefined reference to `_imp___ZN5QMenuC1EP7QWidget'
and so on.
I seems like Qt libraries don't connected to the application.How to fix that?
-
QT += network widgets serialport
Module names should be added/removed in
QT
, notCONFIG
.
And you need to addwidgets
for QMenu since you removedgui
.
[Added]
Ah, seemswidgets
depends ongui
, so adding widgets will add gui again. I guess you should not remove gui if you want use QMenu. -
@tankist said in Application doesn't find Qt libraries during compilation process:
system tray icon
It is not working like that...
QSysTrayIcon
is aQWidget
and therefore needs theQtWidget
module. Even though when your intention is to build a "background" app... The above mentioned class(es) (includingQMenu
what you are probably gonna use as a popup when clicking the icon) requires some GUI components. -
Thank you, guys. It was just my mistake. Now configuration looks like
QT -= gui QT += serialport network widgets CONFIG += c++11 console
and the application build process succeeded.
The only issue is widgets are not created. Application crashed onmenu = new QMenu();
with error
QWidget: Cannot create a QWidget without QApplication
I have no idea what was wrong because I created QApplication object before.
int main(int argc, char *argv[]) { a = new QCoreApplication(argc, argv); sysMon = new SystemMonitor();
Maybe it was wrong idea at all to create console application with system tray icon?
-
@tankist said in Application doesn't find Qt libraries during compilation process:
Maybe it was wrong idea at all to create console application with system tray icon?
Yes, exactly! As @Pl45m4 already posted above.
AndQCoreApplication
is not aQApplication
,QApplication
inheritsQGuiApplication
,QGuiApplication
inheritsQCoreApplication
.
So clearly you cannot use QMenu without gui. -