Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT5.3 did not support "forward declaration"??(Solved)
Forum Updated to NodeBB v4.3 + New Features

QT5.3 did not support "forward declaration"??(Solved)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    ylkevin
    wrote on last edited by
    #1

    Hi Guys

    Run the example project from the book "C++ GUI Programming with Qt4".

    Under QT5 (Qt/Qt5.3.1/Tools/mingw482_32/bin), got many errors like "forward declaration of 'class QLineEdit'"

    Under QT4 ( the same mingw compiler with QT5.3), no errors.

    What happened?

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      ylkevin
      wrote on last edited by
      #2

      @
      09:45:12: Running steps for project find...
      09:45:12: Configuration unchanged, skipping qmake step.
      09:45:12: Starting: "C:\Qt\Qt5.3.1\Tools\mingw482_32\bin\mingw32-make.exe"
      C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/mingw32-make -f Makefile.Debug
      mingw32-make[1]: Entering directory 'D:/qt_test/qt-book/chap02/build-find-Desktop_Qt_5_3_MinGW_32bit-Debug'
      g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\find -I"C:\Qt\Qt5.3.1\5.3\mingw482_32\include" -I"C:\Qt\Qt5.3.1\5.3\mingw482_32\include\QtWidgets" -I"C:\Qt\Qt5.3.1\5.3\mingw482_32\include\QtGui" -I"C:\Qt\Qt5.3.1\5.3\mingw482_32\include\QtCore" -I"debug" -I"." -I"C:\Qt\Qt5.3.1\5.3\mingw482_32\mkspecs\win32-g++" -o debug\finddialog.o ..\find\finddialog.cpp
      ..\find\finddialog.cpp: In constructor 'FindDialog::FindDialog(QWidget*)':
      ..\find\finddialog.cpp:8:41: error: invalid use of incomplete type 'class QLabel'
      label = new QLabel(tr("Find &what:"));
      ^
      In file included from ..\find\finddialog.cpp:3:0:
      ..\find\finddialog.h:7:7: error: forward declaration of 'class QLabel'
      class QLabel;
      ^
      ..\find\finddialog.cpp:9:20: error: invalid use of incomplete type 'class QLineEdit'
      lineEdit = new QLineEdit;
      ^
      In file included from ..\find\finddialog.cpp:3:0:
      ..\find\finddialog.h:8:7: error: forward declaration of 'class QLineEdit'
      class QLineEdit;
      ^
      ..\find\finddialog.cpp:10:10: error: invalid use of incomplete type 'class QLabel'
      label->setBuddy(lineEdit);
      ^
      In file included from ..\find\finddialog.cpp:3:0:
      ..\find\finddialog.h:7:7: error: forward declaration of 'class QLabel'
      class QLabel;
      ^
      ..\find\finddialog.cpp:12:51: error: invalid use of incomplete type 'class QCheckBox'
      caseCheckBox = new QCheckBox(tr("Match &case"));
      ^
      In file included from ..\find\finddialog.cpp:3:0:
      ..\find\finddialog.h:6:7: error: forward declaration of 'class QCheckBox'
      class QCheckBox;
      ^
      ..\find\finddialog.cpp:13:60: error: invalid use of incomplete type 'class QCheckBox'
      backwardCheckBox = new QCheckBox(tr("Search &backward"));
      ^
      In file included from ..\find\finddialog.cpp:3:0:
      ..\find\finddialog.h:6:7: error: forward declaration of 'class QCheckBox'
      class QCheckBox;
      ^
      ..\find\finddialog.cpp:15:45: error: invalid use of incomplete type 'class QPushButton'
      findButton = new QPushButton(tr("&Find"));
      ^
      In file included from C:\Qt\Qt5.3.1\5.3\mingw482_32\include\QtWidgets/QDialog:1:0,
      from ..\find\finddialog.h:4,
      from ..\find\finddialog.cpp:3:
      @

      [andreyc EDIT]: Added @ around log messages.

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        widgets are moved to separate lib in called widgets in Qt 5.0 if you are using the pro file directly from Qt 4.0 make the following entry in the pro file.

        QT += widgets.

        Also ensure that #include <QLabel> exist in the header files.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          ylkevin
          wrote on last edited by
          #4

          Thanks.
          QT += widgets. is already included.
          forward declaration is not supported as:

          //#include <QtGui>
          //class QCheckBox;
          //class QLabel;
          //class QLineEdit;
          //class QPushButton;

          must be replaced by:

          #include <QDialog>
          #include <QLabel>
          #include <QPushButton>
          #include <QLineEdit>
          #include <QCheckBox>
          #include <QHBoxLayout>

          QT4.82 support forward declaration, QT5.3 doesn't.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            Glad that you solved the problem.

            As a side note a forward declaration is a C++ feature not Qt hence Qt cannot support nor not support it.

            All these classes were indirectly defined in QtGui before Qt5.
            In Qt5 they belong to QtWidgets

            So if you would forward declare class QLabel in a header and then include file QLabel or QtWidgets in a source file everything would work.

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              ylkevin
              wrote on last edited by
              #6

              Great Thanks.
              Yes, use QtWidgets to replace QtGui
              All the rest of include files can be replaced.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                On a side note, using module wide include is bad practice since it pulls in every class and thus will slow down compile time. Including the class specific header should be enough.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved