16,240
社区成员
发帖
与我相关
我的任务
分享
son::son(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
fuzi *f = (fuzi*)parentWidget();
bool a = connect(f, SIGNAL(sendData(QString)), this, SLOT(receiveData(QString)));
if (a)
QMessageBox::information(this, "", QString::number(i1)); //弹出一个对话框
else
QMessageBox::information(this, "", "2"); //弹出一个对话框
}
son::~son()
{
}
void son::receiveData(QString data)
{
ui.text->setText(data); //获取传递过来的数据
}
上面的代码是子窗口的cpp的构造函数,显示的对话框是1,就是没有连接
fuzi::fuzi(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
p_s = new son();
connect(ui.send, SIGNAL(clicked()), this, SLOT(send())); //发送数据
}
fuzi::~fuzi()
{
}
void fuzi::send()
{
emit sendData(ui.text->text()); //获取lineEdit的输入并且传递出去
}
这个是父窗口的代码