Close QDialog From Mainwindow



  • Hi All
    I have a mainwindow application and I have created a Qdialog .Now I want to close the dialog from my mainwindow under these conditions

    1.If I click a close dialog button the dialog should close .
    2.If I click mainwindow close button the dialog should close.
    3.I don't if this is possible In case the application is closed through taskmanager the dialog should get closed.

    Here is my dialog invoking code

    //your code here
    NewDialog *dialog = new NewDialog();
    dialog->show();
    

    Any solution is appreciated.
    Thanks
    Shiv




  • Qt Champions 2016

    @Shiv said:

    NewDialog *dialog = new NewDialog();

    You should give it mainwindow as parent to make sure its
    closed if mainwin is closed!

    NewDialog *dialog = new NewDialog(this); /// this being mainwindows

    • 1.If I click a close dialog button the dialog should close .
      default. if u made a true dialog. it does this already.

    • 2.If I click mainwindow close button the dialog should close.
      you should move
      NewDialog *dialog;
      to mainwin .h as member and only do
      dialog = new NewDialog();
      Then in any mainwin function u can do
      dialog->close(); to close it.

    • 3.I don't if this is possible In case the application is closed through taskmanager the dialog should get closed.
      if u give it mainwin as parent , it will be closed too.



  • Hi @mrjj @Ratzz

    Thanks for your kind help I am working on it I reply back after checking

    Thanks
    Shiv


Log in to reply
 

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