简体   繁体   中英

How to access text of comboBox from another QDialog and write it to lineEdit in that Dialog

I need to access the text of combobox in Mainwindow from Dialog. After that, I want to write that text to lineEdit in Dialog. How can I do this?

I tried to handle this with signal/slot. However, I could not fix. I am newbie and need help.

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);
}

I see this qDebug message after I click addChange pushButton:

Project received: "Monitoring"
Software received: "Broadcast"
Project sent: "Monitoring"
Software sent: "Broadcast"

However, lineEdit_proChanged and lineEdit_softChanged are still empty.

I need help to manage this. Thank you in advance.

那是因为你显示一个QDialogAdd_Change addChange; )而连接信号和插槽到另一个( Add_Change *add_change;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM