Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Open a QDialog and then close the parent



  • I have a QMainWindow that opens a bunch of QDialogs for user input that then triggers a specific action, e.g. copying data from a to b. These actions don't have to necessarily block the entire application, so I want to spawn a separate popup Dialog from the initial dialog. The behavior should be like this:

    1. Start Application
    2. Open Dialog
    3. Fill out form fields in the dialog and click 'Ok' to start the action
    4. New ProgressBar dialog pops up and initial dialog closes
    5. Action is running in the background, updating the progress bar in the new dialog

    Unfortunately, I can't manage to get a new QDialog popped up from the initial one without the initial one remaining open.

    MainWindow.cpp

    ...
    void MainWindow::copySlot()
    {
      CopyDialog copy(this);
      copy.exec();
    }
    ...
    

    CopyDialog.cpp

    ...
    void CopyDialog::progress()
    {
      ProgressBarWindow pb("Copy Data", 500);
      pb.exec();
    }
    

    I have played around with the modality and other things. When I'm using show() on the ProgressBarWindow it doesn't even pop up. What am I missing?

    Thanks!


  • Lifetime Qt Champion

    Hi,

    That’s because you allocate your dialogs on the stack so at the end of the function they get destroyed.


Log in to reply