Trouble in #include<QtGui> or #include<QtCore>

  • Hello everybody,

    I am learning Qt programming and confused by the include of QtGui and QtCore with Qt 5.0 SDK.
    In the book C++Qt programming with Qt 4 2nd Edition, it said that if we want to use components such as QCheckBox, QLineEdit, QPushButton or QLabel, we only need to include QtGui at the beginning instead of include individual headers <QCheckBox>, <QLineEdit> etc...
    I tried but it throwed a bunch of errors "no appropriate default constructor available". The problem is only solved by include the individual headers.
    Could any body help me figure out the problem? Me or Qt5.0 has changed that we need to include individually.

    Thanks very much.

  • Qt5 moved a few things around. You need to:
    #include <QtWidgets>

    to include everything or, preferably to minimise build times in 'real' projects :
    #include <QCheckBox>
    #include <QLineEdit>
    // etc.

    You will also need:
    QT += widgets

    in your PRO file.

    Not much else has changed in the widgets.

  • Thank you ChrisW67, your suggestion solved the problem, one a side note is there a link for viewing differences on how to 'include' files when qt5.0 is used.

  • Moderators

    Hi kdk85,

    Details about differences between Qt 4 and Qt 5 are in the porting guide: There are a few different pages, so make sure you read all the "related topics" listed.

  • Thank you JKSH for providing the link

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.