title: Qt error: invalid use of incomplete type 'class QLabel'
body: <p>I'm trying to compile the following program using QtCreater but I get a lots of errors in this program. I got this program from a book and I'm not able to figure out where the error is. Can someone help debug this program.</p>
  
  <p>Here is the FindDialog.h</p>
  
  <pre><code>#ifndef FINDDIALOG_H
  #define FINDDIALOG_H
  
  #include &lt;QDialog&gt;
  
  class QCheckbox;
  class QLabel;
  class QLineEdit;
  class QPushButton;
  
  class FindDialog : public QDialog
  {
      Q_OBJECT
  
  public:
      FindDialog(QWidget *parent = 0);
  
  signals:
      void findNext(const QString &amp;str, Qt::CaseSensitivity cs);
      void findPrevious(const QString &amp;str, Qt::CaseSensitivity cs);
  
  private slots:
      void findClicked();
      void enableFindButton(const QString &amp;text);
  
  private:
      QLabel *label;
      QLineEdit *lineEdit;
      QCheckbox *caseCheckBox;
      QCheckbox *backwardCheckBox;
      QPushButton *findButton;
      QPushButton *closeButton;
  };
  
  #endif
  </code></pre>
  
  <p>FindDialog.cpp</p>
  
  <pre><code>#include &lt;QtGui&gt;
  
  #include "finddialog.h"
  
  FindDialog::FindDialog(QWidget *parent) : QDialog(parent)
  {
      label = new QLabel(tr("Find &amp;what"));
      lineEdit = new QLineEdit;
      label-&gt;setBuddy(lineEdit);
      caseCheckBox = new QCheckbox(tr("Match &amp;case"));
      backwardCheckBox = new QCheckbox(tr("Search &amp;backward"));
      findButton = new QPushButton(tr("&amp;Find"));
      findButton-&gt;setDefault(true);
      findButton-&gt;setEnabled(false);
      closeButton = new QPushButton(tr("Close"));
  
      connect(lineEdit, SIGNAL(textChanged(const QString &amp;)), 
              this, SLOT(enableFindButton(const QString &amp;)));
  
      connect(findButton, SIGNAL(clicked()),
              this, SLOT(findClicked()));
  
      connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
  
      QHBoxLayout *topLeftLayout = new QHBoxLayout;
      topLeftLayout-&gt;addWidget(label);
      topLeftLayout-&gt;addWidget(lineEdit);
  
      QVBoxLayout *leftLayout = new QVBoxLayout;
      leftLayout-&gt;addLayout(topLeftLayout);
      leftLayout-&gt;addWidget(caseCheckBox);
      leftLayout-&gt;addWidget(backwardCheckBox);
  
      QVBoxLayout *rightLayout = new QVBoxLayout;
      rightLayout-&gt;addWidget(findButton);
      rightLayout-&gt;addWidget(closeButton);
      rightLayout-&gt;addStretch();
  
      QHBoxLayout *mainLayout = new QHBoxLayout;
      mainLayout-&gt;addLayout(leftLayout);
      mainLayout-&gt;addLayout(rightLayout);
      setLayout(mainLayout);
  
      setWindowTitle(tr("Find"));
      setFixedHeight(sizeHint().height());
  }
  
  void FindDialog::findClicked()
  {
      QString text = lineEdit-&gt;text();
      Qt::CaseSensitivity cs = caseCheckBox-&gt;isChecked() ? Qt::CaseSensitivity
                                                         : Qt::CaseInsensitive;
      if(backwardCheckBox-&gt;isChecked()) {
          emit findPrevious(text, cs);
      } else {
          emit findNext(text, cs);
      }
  }
  
  void FindDialog::enableFindButton(const QString &amp;text)
  {
      findButton-&gt;setEnabled(!text.isEmpty());
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;QApplication&gt;
  
  #include "findDialog.h"
  
  int main (int argc, char *argv[])
  {
      QApplication app(argc, argv);
      FindDialog *dialog = new FindDialog;
      dialog-&gt;show();
      return app.exec();
  }
  </code></pre>
  
  <p>The errors I get are the following:</p>
  
  <pre><code>finddialog.cpp:21:32: note: candidates are:
  In file included from /usr/include/qt5/QtCore/qabstractanimation.h:45:0,
                   from /usr/include/qt5/QtCore/QtCore:4,
                   from /usr/include/qt5/QtGui/QtGui:4,
                   from finddialog.cpp:1:
  /usr/include/qt5/QtCore/qobject.h:199:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
       static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                      ^
  /usr/include/qt5/QtCore/qobject.h:199:36: note:   no known conversion for argument 1 from ‘QPushButton*’ to ‘const QObject*’
  /usr/include/qt5/QtCore/qobject.h:202:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&amp;, const QObject*, const QMetaMethod&amp;, Qt::ConnectionType)
       static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &amp;signal,
                                      ^
  /usr/include/qt5/QtCore/qobject.h:202:36: note:   no known conversion for argument 1 from ‘QPushButton*’ to ‘const QObject*’
  /usr/include/qt5/QtCore/qobject.h:418:32: note: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
   inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                  ^
  /usr/include/qt5/QtCore/qobject.h:418:32: note:   no known conversion for argument 1 from ‘QPushButton*’ to ‘const QObject*’
  /usr/include/qt5/QtCore/qobject.h:215:43: note: template&lt;class Func1, class Func2&gt; static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, const typename QtPrivate::FunctionPointer&lt;Func2&gt;::Object*, Func2, Qt::ConnectionType)
       static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer&lt;Func1&gt;::Object *sender, Func1 signal,
                                             ^
  /usr/include/qt5/QtCore/qobject.h:215:43: note:   template argument deduction/substitution failed:
  /usr/include/qt5/QtCore/qobject.h: In substitution of ‘template&lt;class Func1, class Func2&gt; static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, const typename QtPrivate::FunctionPointer&lt;Func2&gt;::Object*, Func2, Qt::ConnectionType) [with Func1 = const char*; Func2 = const char*]’:
  finddialog.cpp:21:32:   required from here
  /usr/include/qt5/QtCore/qobject.h:215:43: error: no type named ‘Object’ in ‘struct QtPrivate::FunctionPointer&lt;const char*&gt;’
  /usr/include/qt5/QtCore/qobject.h:245:13: note: template&lt;class Func1, class Func2&gt; static typename QtPrivate::QEnableIf&lt;((int)(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount) &gt;= 0), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, Func2)
               connect(const typename QtPrivate::FunctionPointer&lt;Func1&gt;::Object *sender, Func1 signal, Func2 slot)
               ^
  /usr/include/qt5/QtCore/qobject.h:245:13: note:   template argument deduction/substitution failed:
  finddialog.cpp:21:32: note:   candidate expects 3 arguments, 4 provided
         this, SLOT(findClicked()));
                                  ^
  In file included from /usr/include/qt5/QtCore/qabstractanimation.h:45:0,
                   from /usr/include/qt5/QtCore/QtCore:4,
                   from /usr/include/qt5/QtGui/QtGui:4,
                   from finddialog.cpp:1:
  /usr/include/qt5/QtCore/qobject.h:268:13: note: template&lt;class Func1, class Func2&gt; static typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, Func2)
               connect(const typename QtPrivate::FunctionPointer&lt;Func1&gt;::Object *sender, Func1 signal, Func2 slot)
               ^
  /usr/include/qt5/QtCore/qobject.h:268:13: note:   template argument deduction/substitution failed:
  finddialog.cpp:21:32: note:   candidate expects 3 arguments, 4 provided
         this, SLOT(findClicked()));
                                  ^
  finddialog.cpp:23:61: error: no matching function for call to ‘FindDialog::connect(QPushButton*&amp;, const char [11], FindDialog* const, const char [9])’
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
                                                               ^
  finddialog.cpp:23:61: note: candidates are:
  In file included from /usr/include/qt5/QtCore/qabstractanimation.h:45:0,
                   from /usr/include/qt5/QtCore/QtCore:4,
                   from /usr/include/qt5/QtGui/QtGui:4,
                   from finddialog.cpp:1:
  /usr/include/qt5/QtCore/qobject.h:199:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
       static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                      ^
  /usr/include/qt5/QtCore/qobject.h:199:36: note:   no known conversion for argument 1 from ‘QPushButton*’ to ‘const QObject*’
  /usr/include/qt5/QtCore/qobject.h:202:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&amp;, const QObject*, const QMetaMethod&amp;, Qt::ConnectionType)
       static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &amp;signal,
                                      ^
  /usr/include/qt5/QtCore/qobject.h:202:36: note:   no known conversion for argument 1 from ‘QPushButton*’ to ‘const QObject*’
  /usr/include/qt5/QtCore/qobject.h:418:32: note: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
   inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                  ^
  /usr/include/qt5/QtCore/qobject.h:418:32: note:   no known conversion for argument 1 from ‘QPushButton*’ to ‘const QObject*’
  /usr/include/qt5/QtCore/qobject.h:215:43: note: template&lt;class Func1, class Func2&gt; static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, const typename QtPrivate::FunctionPointer&lt;Func2&gt;::Object*, Func2, Qt::ConnectionType)
       static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer&lt;Func1&gt;::Object *sender, Func1 signal,
                                             ^
  /usr/include/qt5/QtCore/qobject.h:215:43: note:   template argument deduction/substitution failed:
  /usr/include/qt5/QtCore/qobject.h: In substitution of ‘template&lt;class Func1, class Func2&gt; static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, const typename QtPrivate::FunctionPointer&lt;Func2&gt;::Object*, Func2, Qt::ConnectionType) [with Func1 = const char*; Func2 = const char*]’:
  finddialog.cpp:23:61:   required from here
  /usr/include/qt5/QtCore/qobject.h:215:43: error: no type named ‘Object’ in ‘struct QtPrivate::FunctionPointer&lt;const char*&gt;’
  /usr/include/qt5/QtCore/qobject.h:245:13: note: template&lt;class Func1, class Func2&gt; static typename QtPrivate::QEnableIf&lt;((int)(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount) &gt;= 0), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, Func2)
               connect(const typename QtPrivate::FunctionPointer&lt;Func1&gt;::Object *sender, Func1 signal, Func2 slot)
               ^
  /usr/include/qt5/QtCore/qobject.h:245:13: note:   template argument deduction/substitution failed:
  finddialog.cpp:23:61: note:   candidate expects 3 arguments, 4 provided
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
                                                               ^
  In file included from /usr/include/qt5/QtCore/qabstractanimation.h:45:0,
                   from /usr/include/qt5/QtCore/QtCore:4,
                   from /usr/include/qt5/QtGui/QtGui:4,
                   from finddialog.cpp:1:
  /usr/include/qt5/QtCore/qobject.h:268:13: note: template&lt;class Func1, class Func2&gt; static typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, Func2)
               connect(const typename QtPrivate::FunctionPointer&lt;Func1&gt;::Object *sender, Func1 signal, Func2 slot)
               ^
  /usr/include/qt5/QtCore/qobject.h:268:13: note:   template argument deduction/substitution failed:
  finddialog.cpp:23:61: note:   candidate expects 3 arguments, 4 provided
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
                                                               ^
  finddialog.cpp:25:2: error: ‘QHBoxLayout’ was not declared in this scope
    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    ^
  finddialog.cpp:25:15: error: ‘topLeftLayout’ was not declared in this scope
    QHBoxLayout *topLeftLayout = new QHBoxLayout;
                 ^
  finddialog.cpp:25:35: error: expected type-specifier before ‘QHBoxLayout’
    QHBoxLayout *topLeftLayout = new QHBoxLayout;
                                     ^
  finddialog.cpp:25:35: error: expected ‘;’ before ‘QHBoxLayout’
  finddialog.cpp:29:2: error: ‘QVBoxLayout’ was not declared in this scope
    QVBoxLayout *leftLayout = new QVBoxLayout;
    ^
  finddialog.cpp:29:15: error: ‘leftLayout’ was not declared in this scope
    QVBoxLayout *leftLayout = new QVBoxLayout;
                 ^
  finddialog.cpp:29:32: error: expected type-specifier before ‘QVBoxLayout’
    QVBoxLayout *leftLayout = new QVBoxLayout;
                                  ^
  finddialog.cpp:29:32: error: expected ‘;’ before ‘QVBoxLayout’
  finddialog.cpp:34:15: error: ‘rightLayout’ was not declared in this scope
    QVBoxLayout *rightLayout = new QVBoxLayout;
                 ^
  finddialog.cpp:34:33: error: expected type-specifier before ‘QVBoxLayout’
    QVBoxLayout *rightLayout = new QVBoxLayout;
                                   ^
  finddialog.cpp:34:33: error: expected ‘;’ before ‘QVBoxLayout’
  finddialog.cpp:39:15: error: ‘mainLayout’ was not declared in this scope
    QHBoxLayout *mainLayout = new QHBoxLayout;
                 ^
  finddialog.cpp:39:32: error: expected type-specifier before ‘QHBoxLayout’
    QHBoxLayout *mainLayout = new QHBoxLayout;
                                  ^
  finddialog.cpp:39:32: error: expected ‘;’ before ‘QHBoxLayout’
  finddialog.cpp: In member function ‘void FindDialog::findClicked()’:
  finddialog.cpp:50:25: error: invalid use of incomplete type ‘class QLineEdit’
    QString text = lineEdit-&gt;text();
                           ^
  In file included from finddialog.cpp:3:0:
  finddialog.h:8:7: error: forward declaration of ‘class QLineEdit’
   class QLineEdit;
         ^
  finddialog.cpp:51:39: error: invalid use of incomplete type ‘class QCheckbox’
    Qt::CaseSensitivity cs = caseCheckBox-&gt;isChecked() ? Qt::CaseSensitivity
                                         ^
  In file included from finddialog.cpp:3:0:
  finddialog.h:6:7: error: forward declaration of ‘class QCheckbox’
   class QCheckbox;
         ^
  finddialog.cpp:52:17: error: expected primary-expression before ‘:’ token
                   : Qt::CaseInsensitive;
                   ^
  finddialog.cpp:53:21: error: invalid use of incomplete type ‘class QCheckbox’
    if(backwardCheckBox-&gt;isChecked()) {
                       ^
  In file included from finddialog.cpp:3:0:
  finddialog.h:6:7: error: forward declaration of ‘class QCheckbox’
   class QCheckbox;
         ^
  finddialog.cpp: In member function ‘void FindDialog::enableFindButton(const QString&amp;)’:
  finddialog.cpp:62:12: error: invalid use of incomplete type ‘class QPushButton’
    findButton-&gt;setEnabled(!text.isEmpty());
              ^
  In file included from /usr/include/qt5/QtWidgets/QDialog:1:0,
                   from finddialog.h:4,
                   from finddialog.cpp:3:
  /usr/include/qt5/QtWidgets/qdialog.h:52:7: error: forward declaration of ‘class QPushButton’
   class QPushButton;
         ^
  make: *** [finddialog.o] Error 1
  </code></pre>