[Solved]Link errors with Qt Creator on C++ examples out of the box
-
I'm brand new to both Qt and Qt Creator, so forgive my ignorance if you will. I just installed the QtSDK 4.7.3 on Windows 7 and tried to build a hello world program:
@#include <QtGUI/QApplication>
#include <QtGUI/QPushButton>int main(int argc, char *argv[])
{
QApplication app(argc, argv);QPushButton hello("Hello world!"); hello.resize(100, 30); hello.show(); return app.exec();
}
@I immediately get link errors about undefined references to the following symbols:
_imp___ZN12QApplicationC1ERiPPci
_imp___ZN11QPushButtonC1ERK7QStringP7QWidget
_imp___ZN12QApplication4execEv
_imp___ZN12QApplication4execEv
_imp___ZN12QApplicationD1EvI'm not sure how Qt Creator knows what my include and library paths are. I was getting these errors even before adding anything extra to my PATH variable. The only Qt related thing in my PATH was the bin folder for mingw. Clearly, it's finding the header files, but it doesn't seem to be finding the library files. I get the same errors when trying to build the examples as well.
I tried adding the path to the library folder to my PATH variable (in my case it was C:\QtSDK\Desktop\Qt\4.7.3\mingw\lib) but that didn't work.
Any help would be greatly appreciated.
[EDIT: code formatting, please wrap in @-tags, Eddy]
-
(Be sure and wrap your code in "@" tags, not <div> tags)
What does your .pro file look like?
As an aside...
Also, even though Windows' filenames are case-insensitive, you should use
@
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
@rather than "QtGUI"
-
Thanks for the advice. My .pro file is unchanged from the default. It looks like the following:
@QT += core
QT -= gui
TARGET = HelloWorld
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp@
-
You need to remove line 3 from your .pro file. It looks like you started with a console application template, which disables all of the GUI elements by default (and, as such, keeps them from linking.)
You probably don't need line 6 either.
Your best bet would be to use the "Qt Widget -> Qt Gui Application" template when creating a new project.
-
Thanks, that worked. I'll have to read up on project file syntax.