Qt:Qt设计器按钮面板错误

Qt:Qt设计器按钮面板错误,qt,Qt,我已经创建了一个名为“new_dialog”的模式对话框,带有“确定/取消”按钮。现在我想为OK按钮在插槽上工作。我在按钮窗格上单击鼠标右键,从关联菜单中选择“转到插槽命令”;并获取一个错误: 在mainwindow.cpp中找不到具有Ui::new_对话框的类。检查 包括指令 这是翻译成英语的 如何为按钮分配插槽 谢谢 一些代码: mainwindow.cpp中有new.ui和ui_new.h指令: #include "ui_new.h" 从主窗口调用该对话框: void MainWindo

我已经创建了一个名为“new_dialog”的模式对话框,带有“确定/取消”按钮。现在我想为OK按钮在插槽上工作。我在按钮窗格上单击鼠标右键,从关联菜单中选择“转到插槽命令”;并获取一个错误:

在mainwindow.cpp中找不到具有Ui::new_对话框的类。检查 包括指令 这是翻译成英语的

如何为按钮分配插槽

谢谢

一些代码:

mainwindow.cpp中有new.ui和ui_new.h指令:

#include "ui_new.h"
从主窗口调用该对话框:

void MainWindow::on_pushButton_clicked()
{
    QDialog *new_dialog = new QDialog(0,0);
    Ui_New newUi;
    newUi.setupUi(new_dialog);
    new_dialog->exec();
}
ui_new.h:

#ifndef UI_NEW_H
#define UI_NEW_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>

QT_BEGIN_NAMESPACE

class Ui_New
{
public:
    QDialogButtonBox *buttonBox;
    QLabel *label;
    QLabel *label_2;
    QLineEdit *lineEdit;
    QLineEdit *lineEdit_2;

    void setupUi(QDialog *new_dialog)
    {
        if (new_dialog->objectName().isEmpty())
            new_dialog->setObjectName(QString::fromUtf8("Dialog"));
        new_dialog->setWindowModality(Qt::ApplicationModal);
        new_dialog->resize(250, 180);
        new_dialog->setModal(false);
        buttonBox = new QDialogButtonBox(new_dialog);
        buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
        buttonBox->setGeometry(QRect(40, 140, 181, 32));
        buttonBox->setOrientation(Qt::Horizontal);
        buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
        label = new QLabel(new_dialog);
        label->setObjectName(QString::fromUtf8("label"));
        label->setGeometry(QRect(20, 40, 46, 13));
        label_2 = new QLabel(new_dialog);
        label_2->setObjectName(QString::fromUtf8("label_2"));
        label_2->setGeometry(QRect(20, 70, 46, 13));
        lineEdit = new QLineEdit(new_dialog);
        lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
        lineEdit->setGeometry(QRect(70, 40, 113, 20));
        lineEdit_2 = new QLineEdit(new_dialog);
        lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
        lineEdit_2->setGeometry(QRect(70, 70, 113, 20));

        retranslateUi(new_dialog);
        QObject::connect(buttonBox, SIGNAL(accepted()), new_dialog, SLOT(accept()));
        QObject::connect(buttonBox, SIGNAL(rejected()), new_dialog, SLOT(reject()));

        QMetaObject::connectSlotsByName(new_dialog);
    } // setupUi

    void retranslateUi(QDialog *new_dialog)
    {
        new_dialog->setWindowTitle(QApplication::translate("Dialog", "New person", 0, QApplication::UnicodeUTF8));
        label->setText(QApplication::translate("Dialog", "Name", 0, QApplication::UnicodeUTF8));
        label_2->setText(QApplication::translate("Dialog", "Surname", 0, QApplication::UnicodeUTF8));
    } // retranslateUi

};

namespace Ui {
    class new_dialog: public Ui_New {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_NEW_H

您是否创建了从QDialog继承的新对话类??通常,如果您使用QDialog,您不能连接到按钮插槽,但必须连接到主窗口的任何插槽的接受或拒绝信号

QDialog *new_dialog = new QDialog(0,0);
connect(new_dialog,SIGNAL(accepted()),this,SLOT(MySlot()));
注意:这是主窗口指针

如果您创建自己的对话框类,并且有指向按钮的指针,请首先将单击的按钮连接到对话框插槽,然后从那里重定向到MainWindow