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_OBJECT

public:
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_OBJECT

public:
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()
{

}

1个回答

信号和槽写在不同的窗体类里就可以了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问