Results 1 to 5 of 5

Thread: Working with multiple local QDialogs

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Working with multiple local QDialogs

    Hello!

    I would like to declare two local QDialogs by pointers and show them at the same time, and only after the last of them is closed the reading of the code would proceed:

    Qt Code:
    1. QDialog *dia1 = new QDialog(this);
    2. dia1->configure...
    3.  
    4. QDialog *dia2 = new QDialog(this);
    5. dia2->configure...
    6.  
    7. dia1->show();
    8. dia2->show();
    9.  
    10. //The reading of the code stops here while the user uses the two dialogs as it pleases him, and after closing the last of the two the reading of the code proceeds
    11.  
    12. delete dia1;
    13. delete dia2;
    To copy to clipboard, switch view to plain text mode 

    The problem is that I simple don't know how to this without causing some sort of bad consequence. If I try to use exec() for both of them, the second Dialog is opened only after closing the first. If I use show() for both, than the rest of the code will be read even with the dialogs still opened. If I set show() for the first and exec() for the second, than it's impossible to touch in the first QDialog; it will be blocked while I work with the second dialog. setWindowModality() doesn't seems to add any improvement to this situation.

    Is there a possible way of doing this?


    Thanks,

    Momergil

  2. #2
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Working with multiple local QDialogs

    Hi,

    this might be useless advice as I don't know the reason why you want to have the user close two dialogs after one another, but you might consider creating a QDialog subclass that consists of the contents of both your dialogs. Or, if dia1 is supposed to be shown before dia2, you might consider a QWizard.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Working with multiple local QDialogs

    • Make dia1 and dia2 class members
    • make a function which set up the dialogs and show them
    • connect the hidden signals (or QDialog::accepted or or or) of the dialogs to a custom slot
    • there check, if both dialogs where closed/hidden. If so continue with your code.

  4. The following user says thank you to Lykurg for this useful post:

    Momergil (1st April 2013)

  5. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Working with multiple local QDialogs

    Quote Originally Posted by ChiliPalmer View Post
    Hi,

    this might be useless advice as I don't know the reason why you want to have the user close two dialogs after one another, but you might consider creating a QDialog subclass that consists of the contents of both your dialogs. Or, if dia1 is supposed to be shown before dia2, you might consider a QWizard.
    Thanks Chili, but that is of no use for me. I want to give the user the option of moving the two dialogs as he wants around the desktop, not concentrating all data into one QDialog alone. And it's to be shown "at the same time", i.e. the user will be seeing both QDialogs in the screen, not the type of thing QWizard provides.


    Added after 7 minutes:


    Quote Originally Posted by Lykurg View Post
    • Make dia1 and dia2 class members
      ...
    yes, I know how to do this if I declare them class members, but as I put in my question, I'ld like to declare them local, as in my code example.


    Added after 1 13 minutes:


    Quote Originally Posted by Lykurg View Post
    • Make dia1 and dia2 class members
    • make a function which set up the dialogs and show them
    • connect the hidden signals (or QDialog::accepted or or or) of the dialogs to a custom slot
    • there check, if both dialogs where closed/hidden. If so continue with your code.
    Well, at the end I decided to follow this way. Nevertheless I'm still curious about the possibility of doing the way I asked about...

    Thanks,

    Momergil
    Last edited by Momergil; 1st April 2013 at 21:07.

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Working with multiple local QDialogs

    Nevertheless I'm still curious about the possibility of doing the way I asked about...
    Construct your dialog instances as local variables in the method where you show them.
    Connect their accepted() (or rejected(), or whatever dialog closing signal you'd like to handle) signals to a slot (in any class).
    In that slot, call "sender()->deleteLater()" to schedule the instance for deletion.

    When control returns to the event loop, the dialog instance will be deleted. Same thing will happen for the other dialog when the user closes it.

    See QObject::deleteLater().

    Edit: since you will no longer have access to the dialog pointers anywhere except in the accept() slot, there's no way to check if the dialogs have been closed. I'd suggest you could do something simple like have an integer member variable. Set it to zero when you create and show the dialogs, then in the accept() slot, increment it. When it reaches 2, emit another signal that results in the continuation of your code.
    Last edited by d_stranz; 1st April 2013 at 23:42.

  7. The following user says thank you to d_stranz for this useful post:

    Momergil (14th February 2014)

Similar Threads

  1. Replies: 7
    Last Post: 24th September 2012, 08:17
  2. QDialogs are always on top - why?
    By Maximka in forum Newbie
    Replies: 4
    Last Post: 21st February 2010, 17:40
  3. Seg Fault with multiple QDialogs
    By kroenecker in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2009, 15:21
  4. Replies: 1
    Last Post: 18th November 2008, 18:41
  5. How to get local IP
    By naresh in forum Qt Programming
    Replies: 11
    Last Post: 17th May 2006, 16:48

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.