Important: Please read the Qt Code of Conduct -

Can't get rid of ld error: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'

  • Hello

    I use qt-opensource-windows-x86-mingw492-5.5.1.exe on my WinXP laptop on which I previously installed mingw32. I try to build sample program I saw on a book, but I got stuck at this point. Picture for quick explanation:

    link text

    and also, I takes too long to remake the Makefile using qmake -project, I had to quit it after 4-5 minutes.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are not linking the QtWidgets module. Add QT += widgets to your .pro file.

  • Thank you, it worked out. But isn't $ qmake -project supposed to add that line (QT += widgets) to the pro file? How could I know beforehand that QT += widgets was needed in the code in question:

    // helloWorld/main.cpp
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QLabel>
    int main(int argc, char *argv[])
      QApplication a(argc, argv);
      QLabel label("Hello World");;
      return a.exec();

    It's not mentioned in the book either. Could it be because the book was printed on 2007 and the Qt I'm using is version 2015? Thanks.

  • Moderators

    In Qt5 the widgets were pulled from the GUI module, and have been put in their own widgets module. That's why you need to add the widgets in your project file. Note how you include the headers: #include <QtWidgets/...> ;)
    By default qmake will add the core and gui modules only. And you know what module you need from the documentation, see the second line in the table that states: qmake: QT += widgets?

    Kind regards.

Log in to reply