Results 1 to 20 of 41

Thread: closing a dialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: closing a dialog

    Quote Originally Posted by chrisb123 View Post
    I made a plasma app that opens a settings dialog
    I'm trying to close a dialog with a close button
    If I open it like this

    Qt Code:
    1. void test::settings() {
    2. myQtApp *dialog = new myQtApp;
    3. dialog->show();
    4. }
    To copy to clipboard, switch view to plain text mode 

    How can i close it like this

    Qt Code:
    1. myQtApp::myQtApp(QWidget *parent)
    2. {
    3. setupUi(this);
    4. connect( pushButton_close, SIGNAL( clicked() ), this, SLOT( close() ) );
    5. }
    6. void myQtApp::close() {
    7. QMessageBox::about(this,"close",
    8. "this shold close the dialog");
    9. }
    To copy to clipboard, switch view to plain text mode 
    Didn't read up all if you actually fixed your problem already but:
    Qt Code:
    1. myQtApp *dialog = new myQtApp(this);
    2. dialog->setAttribute(Qt::WA_DeleteOnClose);
    3. dialog->show();
    To copy to clipboard, switch view to plain text mode 

    this would solve your problem with deleting dialog.

  2. #2
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    Quote Originally Posted by RSX View Post
    Didn't read up all if you actually fixed your problem already but:
    Qt Code:
    1. myQtApp *dialog = new myQtApp(this);
    2. dialog->setAttribute(Qt::WA_DeleteOnClose);
    3. dialog->show();
    To copy to clipboard, switch view to plain text mode 

    this would solve your problem with deleting dialog.
    That works but how do I test if dialog has been deleted or not, I only want to have one created at any one time

  3. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: closing a dialog

    I think it's deleted when you close the dialog. Qt uses to do a lot of hard work for you

    Well, if so, you can delete it manually.
    Qt Code:
    1. myQtApp *dialog = new myQtApp(this);
    2. dialog->setAttribute(Qt::WA_DeleteOnClose);
    3. dialog->show();
    4. delete dialog;
    5. dialog = 0;
    To copy to clipboard, switch view to plain text mode 

    What I do is to create the dialog on the stack. So it will be deleted for sure when it's out of scope. But I do it with small and temporary dialogs.

    Qt Code:
    1. myQtApp dialog(this);
    2. dialog.setAttribute(Qt::WA_DeleteOnClose);
    3. dialog.show();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    My application is a plasma widget so 99.99% of the time its just the one widget, there is no reason to have anything else just waiting, hidden, invisible or not shown.

    When I use this code
    Qt Code:
    1. m_setapp = new SetApp(this);
    To copy to clipboard, switch view to plain text mode 
    I get this error while compiling
    Qt Code:
    1. mum.cpp: In member function 'void mum::settings()':
    2. mum.cpp:75: error: no matching function for call to 'SetApp::SetApp(mum* const)'
    3. myqtapp.h:34: note: candidates are: SetApp::SetApp(QWidget*)
    4. myqtapp.h:29: note: SetApp::SetApp(const SetApp&)
    To copy to clipboard, switch view to plain text mode 
    But this works ok
    Qt Code:
    1. m_setapp = new SetApp(NULL);
    To copy to clipboard, switch view to plain text mode 

    From what I can tell it's not deleted when it's closed, I have to manually delete it when its closed, then create it again when required

  5. #5
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: closing a dialog

    Right, you have to delete it yourself when you close the application.

    But again: Dont try to be to clever. Get your application up and running and dont bother too much in saving memory when you are not know what you are actually doing. Keeping the dialog in memory will not hurt very much. I'd keep it there so it gets shown faster the second time I open it.
    It's nice to be important but it's more important to be nice.

  6. The following user says thank you to axeljaeger for this useful post:

    chrisb123 (27th October 2009)

  7. #6
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: closing a dialog

    thanks for your help, its been useful
    I still need to learn c++ as object oriented programming is new to me
    As for my application, it does what is needed thats why Ive moved onto improving it

Similar Threads

  1. Closing a dialog using a button
    By srohit24 in forum Qt Programming
    Replies: 5
    Last Post: 21st July 2009, 05:57
  2. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 10:10
  3. Dialog is not closing
    By manmohan in forum Newbie
    Replies: 5
    Last Post: 1st December 2008, 17:04
  4. Replies: 9
    Last Post: 13th August 2008, 18:07
  5. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 10:35

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
  •  
Qt is a trademark of The Qt Company.