netbeans: how to add widgets to QT variable

守給你的承諾、 提交于 2020-01-25 10:47:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!