How to get result from dialog to main windows



  • Hello I maked a dialog with qt creator (Template=Designer Form And Class)
    I put a lineEdit on my dialog.And a Accept OK button.
    in my Main Window ı want get lineEdit of Dialog text.
    I have written like this but didnt work
    void MainWindow::on_pushButton_clicked()
    {
    if(!dialog)
    dialog=new MyDialog(this);
    if(dialog->exec())
    {
    QMessageBox::information(this,"Title",dialog->lineEdit->text());

    }
    }

    Error:
    C:\Users\falco-user\Desktop\cpp\qtdeneme\untitled2\mainwindow.cpp:44: error: 'class MyDialog' has no member named 'lineEdit'
    QMessageBox::information(this,"Title",dialog->lineEdit->text());
    ^



  • Your MyDialog should have a UI file and a UI class. You should add a public getter function to MyDialog that gets the text of the line edit of the UI class. It is not recommended that you expose internals of the implementation of a class in this way. So, your getter should look like:

    QString MyDialog::someText() const
    {
        return m_ui->lineEdit->text();
    }


  • Thank you very much


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.