问题
I have seen posts in which people say that Qt 5 projects are now required to add widgets to QT variable and this is why simple Qt example in netbeans doesn't work: cannot include QtGui/QApplication -> no such file or directory.
how to add this to QT variable? do I have to do it for each project in IDE or in .bashrc or somehowe?
回答1:
the problem was because of link error. it was because it didn't link with QtWidgets.
g++ -m64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64/lib -o dist/Debug/GNU-Linux-x86/QtApplication_2 build/Debug/GNU-Linux-x86/main.o -L/usr/X11R6/lib64 -L/opt/Qt5.0.1/5.0.1/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread
first I have checked that using something from QtCore still works. the code was:
#include <QtCore/QCoreApplication>
int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QCoreApplication a(argc, argv);
// create and show your widgets here
return a.exec();
}
and it was fine, so I knew it is only the linkage error. I still didn't know what to add, as you don't have QtWidget in Qt tab on project Properties in Netbeans. but trial and error showed that it is enough to check the QtOpenGl on this tab (Modules), then it is linked against more libs:
g++ -m64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64 -Wl,-rpath,/opt/Qt5.0.1/5.0.1/gcc_64/lib -o dist/Debug/GNU-Linux-x86/QtApplication_1 build/Debug/GNU-Linux-x86/main.o -L/usr/X11R6/lib64 -L/opt/Qt5.0.1/5.0.1/gcc_64/lib -lQt5OpenGL -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
来源:https://stackoverflow.com/questions/15118720/netbeans-how-to-add-widgets-to-qt-variable