QDialogのサブクラス化

Qt
$ mkdir finddialog
$ cd finddialog
$ vi finddialog.h
#ifdef FINDDIALOG_H
#define FINDDIALOG_H
#include <QDialog>
class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;
class FindDialog : public QDialog
{
  Q_OBJECT
public:
  FindDialog(QWidget *parent = 0);
signals:
  void findNext(const QString &str, Qt::CaseSensitivity cs);
  void fndPrevios(const QString &str, Qt::CaseSensitivity cs);
private slots:
  void findClicked();
  void enableFindButton(const QString &text);
private:
  QLabel *label;
  QLineEdit *lineEdit;
  QCheckBox *caseCheckBox;
  QCheckBox *backwardCheckBox;
  QPushButton *findButton;
  QPushuButton *closeButton;
};
#endif
$ vi finddialog.cpp
#include <QtGui>
#include "finddialog.h"
FindDialog::FindDialog(QWidget *parent)
    : QDialog(parent)
{
  label = new QLabel(tr("Find &what:"));
  lineEdit = new QLineEdit;
  label->setBuddy(lineEdit);
  caseCheckBox = new QCheckBox(tr("Match &case"));
  backwardCheckBox = new QCheckBox(tr("Search  &backward"));
  findButton = new QPushButton(tr("&Find"));
  findButton->setDefault(true);
  findButton->setEnabled(false);
  closeButton = new QPushButton(tr("Close"));
  connect(lineEdit, SIGNAL(textChanged(const QString &)),
          this, SLOT(enableFindButton(const QString &)));
  connect(findButton, SIGNAL(clicked()),
          this, SLOT(findClicked()));
  connect(closeButton, SIGNAL(clicked()),
          this, SLOT(close()));
  QHBoxLayout *topLeftLayout = new QHBoxLayout;
  topLeftLayout->addWidget(label);
  topLeftLayout->addWidget(lineEdit);
  QVBoxLayout *leftLayout = new QVBoxLayout;
  leftLayout->addLayout(topLeftLayout);
  leftLayout->addWidget(caseCheckBox);
  leftLayout->addWidget(backwardCheckBox);
  QVBoxLayout *rightLayout = new QVBoxLayout;
  rightLayout->addWidget(findButton);
  rightLayout->addWidget(closeButton);
  rightLayout->addStretch();
  QHBoxLayout *mainLayout = new QHBoxLayout;
  mainLayout->addLayout(leftLayout);
  mainLayout->addLayout(rightLayout);
  setLayout(mainLayout);
  setwindowTitle(tr("Find"));
  setFixedHeight(sizeHint(),height());
}
void FindDialog::findClicked()
{
  QString text =lineEdit->text();
  Qt::CaseSensitivity cs =
      caseCheckBox->isChecked() ? Qt::CaseSensitive
                                : Qt::CaseInsensitive;
  if (backwardCheckBox->isChecked()) {
    emit findPrevious(text, cs);
  } else {
    emit findNext(text, cs);
  }
}
void FindDialog::enableFindButton(const QString &text)
{
  findButton->setEnabled(!text.isEmpty());
}
$ vi main.cpp
#include <QApplication>
#include "finddialog.h"
int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  FindDialog *dialog = new FindDialog;
  dialog->show();
  return app.exec();
}
$ ls
./  ../  finddialog.cpp  finddialog.h  main.cpp
$ qmake -project
$ ls
./  ../  finddialog.cpp  finddialog.h  finddialog.pro  main.cpp
$ qmake finddialog.pro
Info: creating stash file /home/nakada/Qt4/finddialog/.qmake.stash
$ ls
./  ../  .qmake.stash  Makefile  finddialog.cpp  finddialog.h  finddialog.pro  main.cpp

makeを実行すると下記のエラーとなってしまう。ソースコードがQt4用になっているがインストールしたQtのバージョンが5なので互換性の問題でエラーになっているのだと思われるが…

$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o finddialog.o finddialog.cpp
finddialog.cpp:3:1: error: ‘FindDialog’ does not name a type; did you mean ‘QFontDialog’?
 FindDialog::FindDialog(QWidget *parent)
 ^~~~~~~~~~
 QFontDialog
finddialog.cpp:39:6: error: ‘FindDialog’ has not been declared
 void FindDialog::findClicked()
      ^~~~~~~~~~
finddialog.cpp: In function ‘void findClicked()’:
finddialog.cpp:41:17: error: ‘lineEdit’ was not declared in this scope
   QString text =lineEdit->text();
                 ^~~~~~~~
finddialog.cpp:43:7: error: ‘caseCheckBox’ was not declared in this scope
       caseCheckBox->isChecked() ? Qt::CaseSensitive
       ^~~~~~~~~~~~
finddialog.cpp:45:7: error: ‘backwardCheckBox’ was not declared in this scope
   if (backwardCheckBox->isChecked()) {
       ^~~~~~~~~~~~~~~~
finddialog.cpp:46:10: error: ‘findPrevious’ was not declared in this scope
     emit findPrevious(text, cs);
          ^~~~~~~~~~~~
finddialog.cpp:48:10: error: ‘findNext’ was not declared in this scope
     emit findNext(text, cs);
          ^~~~~~~~
finddialog.cpp:48:10: note: suggested alternative: ‘rindex’
     emit findNext(text, cs);
          ^~~~~~~~
          rindex
finddialog.cpp: At global scope:
finddialog.cpp:51:6: error: ‘FindDialog’ has not been declared
 void FindDialog::enableFindButton(const QString &text)
      ^~~~~~~~~~
finddialog.cpp: In function ‘void enableFindButton(const QString&)’:
finddialog.cpp:53:3: error: ‘findButton’ was not declared in this scope
   findButton->setEnabled(!text.isEmpty());
   ^~~~~~~~~~
make: *** [Makefile:373: finddialog.o] エラー 1

qt4-defaultパッケージをインストールし、Qtのバージョンを4にして再度試してみる。

$ qmake -project
$ ls
./  ../  finddialog.cpp  finddialog.h  finddialog.pro  main.cpp
$ qmake finddialog.pro
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o finddialog.o finddialog.cpp
finddialog.cpp:3:1: error: ‘FindDialog’ does not name a type; did you mean ‘QFontDialog’?
 FindDialog::FindDialog(QWidget *parent)
 ^~~~~~~~~~
 QFontDialog
finddialog.cpp:39:6: error: ‘FindDialog’ has not been declared
 void FindDialog::findClicked()
      ^~~~~~~~~~
finddialog.cpp: In function ‘void findClicked()’:
finddialog.cpp:41:17: error: ‘lineEdit’ was not declared in this scope
   QString text =lineEdit->text();
                 ^~~~~~~~
finddialog.cpp:41:17: note: suggested alternative: ‘QLineEdit’
   QString text =lineEdit->text();
                 ^~~~~~~~
                 QLineEdit
finddialog.cpp:43:7: error: ‘caseCheckBox’ was not declared in this scope
       caseCheckBox->isChecked() ? Qt::CaseSensitive
       ^~~~~~~~~~~~
finddialog.cpp:43:7: note: suggested alternative: ‘QCheckBox’
       caseCheckBox->isChecked() ? Qt::CaseSensitive
       ^~~~~~~~~~~~
       QCheckBox
finddialog.cpp:45:7: error: ‘backwardCheckBox’ was not declared in this scope
   if (backwardCheckBox->isChecked()) {
       ^~~~~~~~~~~~~~~~
finddialog.cpp:45:7: note: suggested alternative: ‘QCheckBox’
   if (backwardCheckBox->isChecked()) {
       ^~~~~~~~~~~~~~~~
       QCheckBox
finddialog.cpp:46:10: error: ‘findPrevious’ was not declared in this scope
     emit findPrevious(text, cs);
          ^~~~~~~~~~~~
finddialog.cpp:48:10: error: ‘findNext’ was not declared in this scope
     emit findNext(text, cs);
          ^~~~~~~~
finddialog.cpp:48:10: note: suggested alternative: ‘rindex’
     emit findNext(text, cs);
          ^~~~~~~~
          rindex
finddialog.cpp: At global scope:
finddialog.cpp:51:6: error: ‘FindDialog’ has not been declared
 void FindDialog::enableFindButton(const QString &text)
      ^~~~~~~~~~
finddialog.cpp: In function ‘void enableFindButton(const QString&)’:
finddialog.cpp:53:3: error: ‘findButton’ was not declared in this scope
   findButton->setEnabled(!text.isEmpty());
   ^~~~~~~~~~
finddialog.cpp:53:3: note: suggested alternative: ‘QRadioButton’
   findButton->setEnabled(!text.isEmpty());
   ^~~~~~~~~~
   QRadioButton
make: *** [Makefile:212: finddialog.o] エラー 1

Qt4に変更してもエラーとなった。何がおかしいのか、現時点で不明…