Undeclared identifier QGridLayout



  • i the header file <QtGui>, but the compiler note me that undeclared identifier QGridLayout

    #include <QtGui>
    QGridLayout *gridlayout = new QGridLayout;

    I know i include <QGridLayout> file can solve it.
    does it mean that if there are many widgets, i must include many header files ?


  • Qt Champions 2016

    @ozzy
    You're using Qt5, which means that you either have to do a full include of <QtWidgets> (widgets are in a separate module now) or include the QGridLayout's header explicitly (which is the better way in my opinion).

    You also might need to add the widgets module to your .pro file, if not done already, like this:
    QT += widgets.

    Kind regards.


  • Moderators

    @ozzy
    to add to @kshegunov post:
    In case you are unsure in which module the class is contained you can quickly check on the very top of the related doc page.



  • @kshegunov

    my.pro file contain the sentence: greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    i change #include <QtGui> to #include <QtWidgets> everything works well.
    Thank you ~


Log in to reply
 

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