Alasdair Kyle Alasdair Kyle - 1 year ago 88
C++ Question

qt command line application compilation

trying to compile this simple qt application

#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
QApplication app(argc, argv);

QPushButton hello("Hello world!");
hello.resize(100, 30);;
return app.exec();

trying to compile with

g++ -I /usr/local/Cellar/qt5/5.8.0_1/Frameworks/QtGui.framework/Headers -o example main.cpp -framework QtGui -framework QtCore

getting error

main.cpp:1:10: fatal error: 'QApplication' file not found
#include <QApplication>
1 error generated.

have checked existence of header file and that it is contained in dir

:Headers ali$ cd /usr/local/Cellar/qt5/5.8.0_1/Frameworks/QtGui.framework/
$ ls
Headers QtGui QtGui.prl Resources Versions

any suggestions as to where im going wrong

Answer Source

The path that you are telling your compiler to look for "QApplication.h" doesn't contain "QApplication.h":

-I /usr/local/Cellar/qt5/5.8.0_1/Frameworks/QtGui.framework/Headers

In a typical install, "QApplication.h" would be in the "QtWidgets", not "QtGui", directory. So you'll probably want to include that directory instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download