Results 1 to 13 of 13

Thread: How to close a QDialog??

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink How to close a QDialog??

    I had created a Qdialog from another .ui file. That is the way i open it.
    Qt Code:
    1. preferences *gamatos = new preferences(this);
    2. gamatos->show();
    To copy to clipboard, switch view to plain text mode 

    So on the QDialog how with a press of a button close the QDialog...


    Also you know on the mainwindow ( where i had a button which opens the QDialog i mentioned before) i have a push button. when you press it opens a QMessageBox. And if you try to click somewhere on the mainwindows it won't let you until you close the QMessageBox. Show how can i do the same when the dialog i said before opens?

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close a QDialog??

    To "show" a dialog as modal, use dialog->exec(); instead of show()
    or in your case gamatos->exec();

    Don't for get to delete gamatos; when the dialog returns to the line after the exec();

    To close your dialog, put a close button on the form. Use a signal/slot to connect it to a function where you close();

  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close a QDialog??

    Sorry we are on the Newbie Section.. Couldn't you tell me with more Details?
    ok i did what you said with the exec instead of show. but how to connect the dialog with the close(). Something like the thing below (which doesn't work)?
    gamatos->addAction("pushButton_3",this,SLOT(close()));

  4. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close a QDialog??

    Did you make your form with Designer? It makes a difference to the example to provide.

  5. #5
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close a QDialog??

    No with the QtDesigner that is in the Qt creator.. You know

  6. #6
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close a QDialog??

    That's the Designer I meant
    Ok, here is what to do: open the form for editing, right click on your close button, left click on "Go to Slot..."
    This will create a slot for you in the .h and .cpp files and immediately show the .cpp slot code in your editor.
    Inside that slot function, put the code: close(); and any other code you need to execute before closing the dialog - your choice.
    Now your dialog is modal (by using the exec() to open it, so no other window is active until you close it, and clicking the 'close' button or whatever you called it, will close your dialog.
    This is the cheap and easy way of making your close or cancel button work.
    Does that do it?

  7. #7
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close a QDialog??

    i know about the go slot and all that.. ok i added just close(); and the button doesn't do enything..

    Qt Code:
    1. void preferences::on_pushButton_3_clicked()
    2. {
    3. close();
    4. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close a QDialog??

    Ok, try this then:

    <yourdialogname>::close();

  9. #9
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close a QDialog??

    Qt Code:
    1. void preferences::on_pushButton_3_clicked()
    2. {
    3. <gamatos>::close();
    4. }
    To copy to clipboard, switch view to plain text mode 

    4 errors :P

    And if i do that

    Qt Code:
    1. void preferences::on_pushButton_3_clicked()
    2. {
    3. gamatos::close();
    4. }
    To copy to clipboard, switch view to plain text mode 

    It says gamatos was not declared on this scope...
    Attached Images Attached Images

  10. #10
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close a QDialog??

    Bong, the <> is just notation to indicate this is where to insert your value.

    What is the name of your dialog class?

  11. #11
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close a QDialog??

    ok on my friend's laptop had worked with close(); so leave it... can you now answer to the second question?

    Quote Originally Posted by Bong.Da.City View Post


    Also you know on the mainwindow ( where i had a button which opens the QDialog i mentioned before) i have a push button. when you press it opens a QMessageBox. And if you try to click somewhere on the mainwindows it won't let you until you close the QMessageBox. Show how can i do the same when the dialog i said before opens?

  12. #12
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close a QDialog??

    I think we already covered that. It's a modal vs non-modal dialog issue.
    Modal dialogs - shown with exec(); won't let you activate any other window in the application until you close them, exactly as you described the message box behavior. Non-modal are the opposite. You can leave them open and go to other windows in the application.
    There are application reasons to use both kinds.
    When I said to show your dialog with exec(); that was to make it modal as you described the behavior you wanted.
    See http://doc.trolltech.com/4.5/qdialog.html#details

  13. #13
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to close a QDialog??

    Ok i didn't understand it before.. Thanks it works

Similar Threads

  1. How to close a local QDialog?
    By MorrisLiang in forum Newbie
    Replies: 2
    Last Post: 23rd August 2010, 11:19
  2. Deleting QDialog object on close
    By ahmdsd_ostora in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2010, 10:55
  3. How can I avoid a QDialog close?
    By ricardo in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2009, 20:29
  4. QDialog not showing close button on Mac
    By manojmka in forum Qt Programming
    Replies: 2
    Last Post: 17th September 2008, 13:56
  5. Replies: 1
    Last Post: 7th July 2007, 10:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.