私は Qt プログラミングの初心者です。Qt を使用した GUI プログラミングに関する本を読みました。ダイアログの作成に問題があります。サンプルコードは次のとおりです。
// gotocell.h
#ifndef GOTOCELL_H
#define GOTOCELL_H
#include <QDialog>
#include <QtWidgets>
#include "ui_gotocell.h"
class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
{
Q_OBJECT
public:
GoToCellDialog (QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
};
#endif // GOTOCELL_H
// gotocell.cpp
#include <QtWidgets>
#include "gotocell.h"
#include <QtWidgets>
GoToCellDialog::GoToCellDialog (QWidget *parent):
QDialog (parent)
{
setupUi(this);
QRegExp regExp ("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp, this));
connect (okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect (cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
void GoToCellDialog::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
// main.cpp
#include "gotocell.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GoToCellDialog *dialog = new GoToCellDialog;
dialog->show();
return a.exec();
}
しかし、コンパイルすると、エラーがあります: no known conversion for argument 1 from 'GoToCellDialog* const' to 'QMainWindow*'
at setupUi()
function. Qt Creator のデザイナーが QDialog ではなく QMainWindow を作成したためだと思います。そこで、GoToCellDialog クラスを QMainWindow に変更しました。しかし、QMainWindow には「受諾」、「拒否」という名前のスロットはありません。誰でも私を助けることができますか?