Important: Please read the Qt Code of Conduct -

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;
            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 function main': test.cpp:(.text.startup+0x27): undefined reference toQApplication::QApplication(int&, char**, int)'
    test.cpp:(.text.startup+0x31): undefined reference to QTextEdit::QTextEdit(QWidget*)' test.cpp:(.text.startup+0x39): undefined reference toQWidget::show()'
    test.cpp:(.text.startup+0x3e): undefined reference to QApplication::exec()' test.cpp:(.text.startup+0x49): undefined reference toQTextEdit::~QTextEdit()'
    test.cpp:(.text.startup+0x51): undefined reference to QApplication::~QApplication()' test.cpp:(.text.startup+0x68): undefined reference toQApplication::~QApplication()'
    test.cpp:(.text.startup+0x7b): undefined reference to `QTextEdit::~QTextEdit()'
    collect2: error: ld returned 1 exit status
    make: *** [QTCode] Error 1

    I am not sure if this is a problem with installation. I would be grateful for any help! Thank you!

  • @SidRama
    Hi and welcome to devnet

    There is actually an example for QTextEdit available.

    What do you have in your .pro file?

  • Hi!
    Actually, the above program is from an example:

    This is the contents of the .pro file:

    TEMPLATE = app
    TARGET = QTCode
    SOURCES += test.cpp

    In the folder I have a Makefile, a 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.

  • Lifetime Qt Champion

    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.

Log in to reply