我用designer制作相应的ui,然后转为*.h文件,在些基础之上,继承该类,最终是想在此desinger的对话框上点击一命令按钮后再弹出一个对话框。但编译后,提示“没有合适的默认构造函数可用",请各位看官,过客,高手指点
源码如下:
(1)GotoCellDialog.h
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include <QDialog>
//#include "Ui_GotoCellDialog.h"
namespace Ui
{
class GotoCellDialog;
}
class GotoCellDialog :public QDialog
{
Q_OBJECT
public:
GotoCellDialog(QWidget *parent =0);
~GotoCellDialog();
private:
Ui::GotoCellDialog *ui;
};
#endif
(2)GotoCellDialog.cpp
#include <QMessageBox>
#include "GotoCellDialog.h"
#include "Ui_GotoCellDialog.h"
#include <QDialog>
//#include <QtGui>
GotoCellDialog::GotoCellDialog(QWidget *parent):QDialog(parent),ui(new Ui::GotoCellDialog)//注,------此句报错,无合适的构造函数可用
{
ui->setupUi(this);
//ui->retranslateUi(this);
//connect(m_pbtest, SIGNAL(clicked()), this, SLOT(OnTest()));
}
GotoCellDialog::~GotoCellDialog()
{
delete ui;
}
/*
void GotoCellDialog::OnTest()
{
QMessageBox::about(this,tr("hello"),tr("hello"));
}*/
(3)Ui_GotoCellDialog.h
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include <QVariant>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include <QComboBox>
#include <QDialog>
#include <QHeaderView>
#include <QLabel>
#include <QPushButton>
#include <QTextEdit>
QT_BEGIN_NAMESPACE
class Ui_GotoCellDialog
{
public:
QLabel *label;
QLabel *label_2;
QTextEdit *m_a1;
QTextEdit *m_a2;
QTextEdit *m_a3;
QLabel *label_4;
QLabel *label_3;
QComboBox *m_cb1;
QComboBox *m_cb2;
QPushButton *m_pbtest;
QPushButton *m_pb1;
QPushButton *m_pb2;
QPushButton *m_pb3;
QPushButton *m_pb4;
QPushButton *m_pbreturn;
void setupUi(QDialog *GotoCellDialog)
{
if (GotoCellDialog->objectName().isEmpty())
GotoCellDialog->setObjectName(QString::fromUtf8("GotoCellDialog"));
GotoCellDialog->resize(509, 359);
label = new QLabel(GotoCellDialog);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(20, 30, 41, 16));
...
...
...
retranslateUi(GotoCellDialog);
QObject::connect(m_pbreturn, SIGNAL(clicked()), GotoCellDialog, SLOT(accept()));
QMetaObject::connectSlotsByName(GotoCellDialog);
} // setupUi
void retranslateUi(QDialog *GotoCellDialog)
{
GotoCellDialog->setWindowTitle(QApplication::translate("GotoCellDialog", "Dialog", 0, QApplication::UnicodeUTF8));
...
...
...
Q_UNUSED(GotoCellDialog);
} // retranslateUi
};
namespace Ui {
class GotoCellDialog: public Ui_GotoCellDialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_GotoCellDialog_H
编译后报错:
正在编译...
GotoCellDialog.cpp
.\GotoCellDialog.cpp(7) : error C2512: “Ui::GotoCellDialog”: 没有合适的默认构造函数可用