c ++ - How to return a value to a previous window in Qt?

2

Hello, I'm developing a project where I will have many calls to new windows and need to recover a value of these windows to the main window (MainWindow). The problem is that it becomes impossible to get the returned value because, when closing the new window, the value is lost with its destructor and does not return to the main window.

EDIT2:

My code for the new window where I return a value (tamveicdialog.cpp):

int TamVeicDialog::getLargura(){
    return this->largura;
}

void TamVeicDialog::on_ButtonSalvar_clicked(){
    this->close();
}

Call my new window in the main window:

void mainwindow::on_ButtonTamVeic_clicked(){

    TamVeicDialog *tamVeic = new TamVeicDialog();
    tamVeic->setFixedSize(696, 368);
    tamVeic->reset(); // seta alguns valores de atributos da nova janela // 
    tamVeic->show();
    int larg = tamVeic->getLargura();

    qDebug() << "Largura retornada: " << larg;
}

The idea is to click save in the TamVeic window, it returns the width value for MainWindow. Would anyone know how to return this value to my Mainwindow? Thank you in advance.

Note: Although my window has a dialog in its declaration, it is QWidget type, I think this question may have caused problems to understand my problem.

    
asked by anonymous 29.08.2016 / 16:34

1 answer

1

My problem was simple resolution. I added the tamVeic->exec(); line after calling tamVeic->show(); , which allowed the value to be returned to the main window. I also had to change the type (the inheritance) from QWidget to QDialog to use the exec(); method. This method blocks the execution of the caller until the window is closed by the user.

    
29.08.2016 / 20:30