我需要从Dialog访问Mainwindow中组合框的文本。之后,我想将该文本写入Dialog中的lineEdit中。我该怎么办?
我试图用信号/插槽来处理。但是,我无法修复。我是新手,需要帮助。
projects.h
signals:
void get_name_pro(const QString &);
void get_name_soft(const QString &);
private slots:
void on_comboBox_projects_currentIndexChanged(const QString &arg1);
void on_pushButton_addChange_clicked();
void on_comboBox_software_activated(int index);
void on_comboBox_software_currentIndexChanged(const QString &arg1);
void popUp_Change_Note();
void popUp_Report();
projects.cpp
void Projects::on_pushButton_addChange_clicked()
{
Add_Change addChange;
addChange.setModal(true);
addChange.exec();
QString data_pro = ui->comboBox_projects->currentText();
QString data_soft = ui->comboBox_software->currentText();
//QString data_soft = ui->tableView_projectDetails->model()->data(ui->tableView_projectDetails->model()->index(0,0)).toString();
Add_Change *add_change;
add_change = new Add_Change(this);
connect (this, SIGNAL( get_name_pro( const QString & ) ), add_change, SLOT( set_text_pro( const QString & ) ) );
connect (this, SIGNAL( get_name_soft( const QString & ) ), add_change, SLOT( set_text_soft( const QString & ) ) );
//connect(this, &Projects::get_name_pro, add_change, &Add_Change::set_text_pro);
//connect(this, &Projects::get_name_soft, add_change, &Add_Change::set_text_soft);
emit get_name_pro(data_pro);
emit get_name_soft(data_soft);
qDebug() << "Project sent:" << data_pro;
qDebug() << "Software sent:" << data_soft;
}
add_change.h
public slots:
void set_text_pro(const QString & text_pro);
void set_text_soft(const QString & text_soft);
private slots:
void on_toolButton_uploadReport_clicked();
void on_pushButton_save_clicked();
void on_pushButton_clean_clicked();
add_change.cpp
void Add_Change::set_text_pro(const QString & text_pro)
{
qDebug() << "Project received:" << text_pro;
ui->lineEdit_proChanged->setText(text_pro);
}
void Add_Change::set_text_soft(const QString & text_soft)
{
qDebug() << "Software received:" << text_soft;
ui->lineEdit_softChanged->setText(text_soft);
}
单击addChange按钮后,我看到以下qDebug消息:
Project received: "Monitoring"
Software received: "Broadcast"
Project sent: "Monitoring"
Software sent: "Broadcast"
但是, lineEdit_proChanged 和 lineEdit_softChanged 仍然为空。
我需要帮助来解决这个问题。预先谢谢你。
答案 0 :(得分:0)
那是因为您在将信号和插槽连接到另一QDialog
的同时显示了一个Add_Change addChange;
(Add_Change *add_change;
)