Please nominate your Qt Champions for 2021!

Undefined reference to `QApplication::QApplication(int&, char**, int)

  • Hello everyone. My name is Evgeny.
    I have the same problem: undefined reference to `QApplication::QApplication(int&, char**, int), and more than.
    I have read some forums, but don't understand something.
    What I should do in Qt-SDK to solve this problem?

    Thanks a lot.

    OS: Linux Debian
    QT-version: 4.7.1

  • Hi Evgeny,

    Could you post code which is causing problems?

  • The error says you're trying to use a QApplication constructor that does not exist. Probably there is an error in one of the arguments. Post a few lines of you code, so we can check and help more :-)

  • Seems that you do not link against QtGui lib. Did you create a .pro file with "qmake -project"?

    There are some examples in the "Getting Started Programming with Qt": guide. Translations of this guide are available in this "wiki page":

  • [quote author="Volker" date="1291893521"]Seems that you do not link against QtGui lib. Did you create a .pro file with "qmake -project".

    Good shot, Volker!
    Of course, 'undefined reference to blablalba' is a linker error. e.ustimenko, forget about what I said (but post the code, if you have other issues).

    SOURCES +=

    HEADERS +=


    target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/Server/Server
    sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS
    sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/Server/server
    INSTALLS += target sources

    symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)

    QT -= gui
    QT += network

    #include <QtGui/QApplication>
    #include <QtCore>

    #include <stdlib.h>

    #include "dialog.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);
    Dialog dialog;;
    return dialog.exec();

  • e.ustimenko, why QT -= gui ? Doing that, you do not link against QtGui (exactly what Volker pointed out)

  • What I should write?

  • Delete the line "QT -= gui" from your .pro file, run qmake again and then make.

    Could you please put your code in @-Tags, that improves readabilitiy, because it's pretty formatted. (You can edit your post afterwards).

  • [quote author="e.ustimenko" date="1291897495"]What I should write?[/quote]

    As you want to use QtGui (QApplication is part of it), remove the line QT -= gui.

    QtCore and QtGui are added by default, so this line only makes sense if you really do not want to use QtGui in you app. In this case, you should use QCoreApplication instead of QApplication.

  • Thank you for answers.

Log in to reply