问题描述
- Qt 怎么在两个对话框之间传递
-
求大神帮忙看看,为什么点击changeInDialog.ui的确定按钮,ChangeConfig不能输出123呢?定义了两个对话框changeindialog和ChangeConfig,我想实现点击changeInDialog.ui的确定按钮,ChangeConfig.ui对话框响应并输出123。
#ifndef CHANGEINDIALOG_H
#define CHANGEINDIALOG_H#include
#include "ui_changeindialog.h"class changeInDialog : public QDialog
{
Q_OBJECTpublic:
changeInDialog(QWidget *parent = 0);
~changeInDialog();public slots:
void shownames();signals:
void cop();public:
Ui::changeInDialog ui1;
};#endif // CHANGEINDIALOG_H
#include "changeindialog.h"
#include "changeconfig.h"
#include "qdebug.h"
#include "qstring.h"changeInDialog::changeInDialog(QWidget *parent)
: QDialog(parent)
{ui1.setupUi(this);
connect(ui1.pushOK,SIGNAL(clicked()),this,SLOT(shownames()));
}
void changeInDialog::shownames()
{
emit cop();
}changeInDialog::~changeInDialog()
{}
#ifndef CHANGECONFIG_H
#define CHANGECONFIG_H#include
#include "ui_changeconfig.h"class ChangeConfig : public QDialog
{
Q_OBJECTpublic:
ChangeConfig(QWidget *parent = 0, Qt::WFlags flags = 0);
~ChangeConfig();public slots:
void display();
public:
Ui::ChangeConfigClass ui;
};#endif // CHANGECONFIG_H
#include "changeconfig.h"
#include "changeindialog.h"
#include "qdebug.h"ChangeConfig::ChangeConfig(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
changeInDialog cconfigIn;
connect(&cconfigIn,SIGNAL(cop()),this,SLOT(display()));
}void ChangeConfig::display()
{qDebug()<<123;
}
ChangeConfig::~ChangeConfig()
{}
解决方案
对对话框之间的信息传递
对对话框之间的信息传递
第七节 对话框之间的数据传递
解决方案二:
信号和槽写在不同的窗体类里就可以了