c++ class forward declaration and invalid use of incomplete type

时间:2022-05-18 16:11:56
08:23:56:Running steps for project dialog...08:23:56:Configuration unchanged, skipping qmake step.08:23:56:Starting:"/usr/bin/make"-w make:Entering directory `/home/entel/program/c++/dialog-build-Desktop_Qt_5_0_1_GCC_32bit-Debug' g++-c -pipe -g -Wall-W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt5.0.1/5.0.1/gcc/mkspecs/linux-g++-I../dialog -I/opt/Qt5.0.1/5.0.1/gcc/include -I/opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets-I/opt/Qt5.0.1/5.0.1/gcc/include/QtGui-I/opt/Qt5.0.1/5.0.1/gcc/include/QtCore-I.-I.-I.-o dialog.o ../dialog/dialog.cpp ../dialog/dialog.cpp:In constructor 'FindDialog::FindDialog(QWidget*)':../dialog/dialog.cpp:5:40: error: invalid use of incomplete type 'class QLabel'In file included from ../dialog/dialog.cpp:1:0:../dialog/dialog.h:9:7: error: forward declaration of 'class QLabel'../dialog/dialog.cpp:6:20: error: invalid use of incomplete type 'class QLineEdit'In file included from ../dialog/dialog.cpp:1:0:../dialog/dialog.h:10:7: error: forward declaration of 'class QLineEdit'../dialog/dialog.cpp:7:10: error: invalid use of incomplete type 'class QLabel'In file included from ../dialog/dialog.cpp:1:0:../dialog/dialog.h:9:7: error: forward declaration of 'class QLabel'../dialog/dialog.cpp:9:47: error: invalid use of incomplete type 'class QCheckBox'In file included from ../dialog/dialog.cpp:1:0:../dialog/dialog.h:8:7: error: forward declaration of 'class QCheckBox'../dialog/dialog.cpp:10:60: error: invalid use of incomplete type 'class QCheckBox'In file included from ../dialog/dialog.cpp:1:0:../dialog/dialog.h:8:7: error: forward declaration of 'class QCheckBox'../dialog/dialog.cpp:12:45: error: invalid use of incomplete type 'class QPushButton'In file included from /opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/QDialog:1:0, from ../dialog/dialog.h:4, from ../dialog/dialog.cpp:1:/opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/qdialog.h:52:7: error: forward declaration of 'class QPushButton'../dialog/dialog.cpp:13:15: error: invalid use of incomplete type 'class QPushButton'In file included from /opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/QDialog:1:0, from ../dialog/dialog.h:4, from ../dialog/dialog.cpp:1:/opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/qdialog.h:52:7: error: forward declaration of 'class QPushButton'../dialog/dialog.cpp:14:15: error: invalid use of incomplete type 'class QPushButton'In file included from /opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/QDialog:1:0, from ../dialog/dialog.h:4, from ../dialog/dialog.cpp:1:/opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/qdialog.h:52:7: error: forward declaration of 'class QPushButton'../dialog/dialog.cpp:16:46: error: invalid use of incomplete type 'class QPushButton'In file included from /opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/QDialog:1:0, from ../dialog/dialog.h:4, from ../dialog/dialog.cpp:1:/opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/qdialog.h:52:7: error: forward declaration of 'class QPushButton'../dialog/dialog.cpp:17:103: error: no matching function for call to 'FindDialog::connect(QLineEdit*&, const char*, FindDialog* const, const char*)'../dialog/dialog.cpp:17:103: note: candidates are:In file included from /opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/qwidget.h:46:0, from /opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/qdialog.h:45, from /opt/Qt5.0.1/5.0.1/gcc/include/QtWidgets/QDialog:1, from ../dialog/dialog.h:4, from ../dialog/dialog.cpp:1:/opt/Qt5.0.1/5.0.1/gcc/include/QtCore/qobject.h:211:36: note:staticQMetaObject::ConnectionQObject::connect(constQObject*,constchar*,con
解决办法是在头文件里加人类包含

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