Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Close QDialog From Mainwindow
Forum Updated to NodeBB v4.3 + New Features

Close QDialog From Mainwindow

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shiv
    wrote on last edited by
    #1

    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

    RatzzR 1 Reply Last reply
    0
    • S Shiv

      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

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #2

      @Shiv
      1. You can use dialog->close();
      2.remplement closeEvent doc.qt.io/qt-4.8/qwidget.html#closeEvent
      3.this might help http://stackoverflow.com/questions/17061572/how-to-close-correctly-a-qt-program

      --Alles ist gut.

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        @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.

        1 Reply Last reply
        2
        • S Offline
          S Offline
          Shiv
          wrote on last edited by
          #4

          Hi @mrjj @Ratzz

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

          Thanks
          Shiv

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved