Problem with Executing Example [SOLVED]
-
I have installed QT from source and everything seems fine. This is the test code I am trying to run:
#include <QApplication>
#include <QTextEdit>int main(int argv, char **args) { QApplication app(argv, args); QTextEdit textEdit; textEdit.show(); return app.exec(); }
I saved this in a folder called QTCode. I then used qmake -project and qmake. However, when I finally call make I get the following error:
g++ -Wl,-O1 -Wl,-rpath,/usr/local/Qt-5.4.1/lib -o QTCode test.o -L/usr/local/Qt-5.4.1/lib -lQt5Gui -lQt5Core -lGL -lpthread
test.o: In functionmain': test.cpp:(.text.startup+0x27): undefined reference to
QApplication::QApplication(int&, char**, int)'
test.cpp:(.text.startup+0x31): undefined reference toQTextEdit::QTextEdit(QWidget*)' test.cpp:(.text.startup+0x39): undefined reference to
QWidget::show()'
test.cpp:(.text.startup+0x3e): undefined reference toQApplication::exec()' test.cpp:(.text.startup+0x49): undefined reference to
QTextEdit::~QTextEdit()'
test.cpp:(.text.startup+0x51): undefined reference toQApplication::~QApplication()' test.cpp:(.text.startup+0x68): undefined reference to
QApplication::~QApplication()'
test.cpp:(.text.startup+0x7b): undefined reference to `QTextEdit::~QTextEdit()'
collect2: error: ld returned 1 exit status
make: *** [QTCode] Error 1I am not sure if this is a problem with installation. I would be grateful for any help! Thank you!
-
@SidRama
Hi and welcome to devnetThere is actually an example for QTextEdit available.
What do you have in your .pro file?
-
Hi!
Actually, the above program is from an example:
http://doc.qt.io/qt-4.8/gettingstartedqt.htmlThis is the contents of the .pro file:
TEMPLATE = app
TARGET = QTCode
INCLUDEPATH += .
#Input
SOURCES += test.cppIn the folder I have a Makefile, a QTCode.pro file, test.cpp and test.o
Thank you!
-
@SidRama
You should use the new example. There are only a couple of differences between Qt4 and Qt5. However, a major difference is probably in the .pro file. That may explain your problem. -
Hi and welcome to devnet,
@koahnig is right, with Qt 5, the widgets have now their own module separated from gui, so the pro files from Qt 4 won't have
QT += widgets
that is needed to compile with Qt 5. -
Hi!
Thank you so much! It turns out that I hadn't installed QT properly and the CLASSPATH was messed up.