0

私は 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 には「受諾」、「拒否」という名前のスロットはありません。誰でも私を助けることができますか?

4

1 に答える 1

0

If you want to display a Dialog as main window you have two choices: 1. make the whole main window QDialog based 2. design the Dialog separately and set it as the main windows central Widget (QMainWindow->setCentralWidget()).

In both cases you still have the problem what semantics you give to the OK and Cancel buttons. Generally it may be a better idea to consider what the main window of the application should contain, and design the dialogs later.

于 2013-08-04T17:30:47.200 に答える