Problems when trying to compile cpp files using qt headers
Hello. I have mandrake 9.1. I've tried to use qt assistant to learn gui programming (at least to see what it is). I have done everything exactly as it was written in the tutorial #1 of the qt assistant. But when i try to compile the file HelloWorld.cpp using make or g++ there are lots of errors saying about undefined references. What's wrong? Thanks in advance.
Here are the messages produced: [blade@localhost qt]$ qmake -project [blade@localhost qt]$ qmake [blade@localhost qt]$ make g++ -o qt qt.o -L/usr/X11R6/lib -lXext -lX11 -lm qt.o(.text+0x30): In function `main': : undefined reference to `QApplication::QApplication[in-charge](int&, char**)' qt.o(.text+0x40): In function `main': : undefined reference to `QString::QString[in-charge](char const*)' qt.o(.text+0x62): In function `main': : undefined reference to `QPushButton::QPushButton[in-charge](QString const&, QWidget*, char const*)' qt.o(.text+0x7d): In function `main': : undefined reference to `QString::shared_null' qt.o(.text+0x87): In function `main': : undefined reference to `QStringData::deleteSelf()' qt.o(.text+0xa4): In function `main': : undefined reference to `QPushButton::resize(int, int)' qt.o(.text+0xb0): In function `main': : undefined reference to `QApplication::setMainWidget(QWidget*)' qt.o(.text+0xb8): In function `main': : undefined reference to `QWidget::show()' qt.o(.text+0xc0): In function `main': : undefined reference to `QApplication::exec()' qt.o(.text+0xca): In function `main': : undefined reference to `QPushButton::~QPushButton [in-charge]()' qt.o(.text+0xd2): In function `main': : undefined reference to `QApplication::~QApplication [in-charge]()' qt.o(.text+0xfe): In function `main': : undefined reference to `QString::shared_null' qt.o(.text+0x108): In function `main': : undefined reference to `QStringData::deleteSelf()' qt.o(.text+0x116): In function `main': : undefined reference to `QPushButton::~QPushButton [in-charge]()' qt.o(.text+0x126): In function `main': : undefined reference to `QApplication::~QApplication [in-charge]()' collect2: ld returned 1 exit status make: *** [qt] Error 1 Report this pos |
judging from the error messages i think you havent included the lines...
#include <qappplication.h> #include <qpushbutton.h> Anyway if you are using Qt Designer you should 1. Create a new project and design the interface 2. Insert a "C++ Main" source file (just the way you inserted the dialog box or main window" 3. qmake -project 4. qmake 5. make 6. run the program Everything should work fine. |
Also check if g++ can reach the library files of Qt
usually qmake takes care of this but this might also be your problem. append the path of the qt library with -L/<path> |
All times are GMT -5. The time now is 02:34 PM. |