Results 1 to 5 of 5

Thread: Holding Program until QWidget is closeed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2013
    Posts
    20
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Holding Program until QWidget is closeed

    Hey Guys!

    I am using a QWidget for collecting User Input. Now at a certain point I want the program to wait until the QWidget is closed before continuing. In contrast to the QDialog class the QWidget class does not offer an exec() method. Is there another way I can achieve the "waiting" behaviour?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Holding Program until QWidget is closeed

    Event loop driven programs are always "running", exec() only makes it look like it is not "stopping" at some point.

    Instead of writing code "sychronously", e.g. like this

    Qt Code:
    1. // to one thing
    2.  
    3. dialog.exec();
    4.  
    5. // do anoher thing
    To copy to clipboard, switch view to plain text mode 

    you can always split the two parts into two methods and let the second part be triggered by a signal, e.g. like this

    Qt Code:
    1. void MyClass::method1()
    2. {
    3. // to one thing
    4. }
    5.  
    6. void MyClass::method2()
    7. {
    8. // to another thing
    9. }
    To copy to clipboard, switch view to plain text mode 

    The trigger for the execution of the slot method2() is then a signal from the input widget, that it emits when it is satisfied with the input.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    FreddyKay (7th August 2013)

  4. #3
    Join Date
    Jun 2013
    Posts
    20
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Holding Program until QWidget is closeed

    First of all, thank you for your suggestion! I also thought of that workaround, I just wondered whether there is another, more elegant way of recreating "exec()" possibly using some Qt methods I wasn't aware of. Anyway thanks alot!

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Holding Program until QWidget is closeed

    You can do the same thing QDialog is doing internally, i.e. using a nested event loop.

    Qt Code:
    1. connect(myWidget, SIGNAL(mySignal()), &loop, SLOT(quit()));
    2. loop.exec();
    To copy to clipboard, switch view to plain text mode 

    As with QDialog::exec() be aware that this just moving event processing, not halting it.

    In most cases it is safer to go for an asynchronous approach instead of pseudo-synchronous.
    So what you consider a work around now is actually the more elegant solution

    Cheers,
    _

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

    FreddyKay (7th August 2013)

  7. #5
    Join Date
    Jun 2013
    Posts
    20
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Holding Program until QWidget is closeed

    This seems to be what I was looking for. I will give it a try, though its not as straightforward as the first approach, it might actually save me a bit of work Thanks again!

Similar Threads

  1. Replies: 2
    Last Post: 24th January 2010, 12:46
  2. Replies: 6
    Last Post: 22nd September 2008, 11:53
  3. figuring out who's holding up
    By baray98 in forum General Programming
    Replies: 4
    Last Post: 7th December 2007, 18:29
  4. QTreeView: Holding a line on screen
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 11:42
  5. what item QCanvasItemList is holding..
    By Kapil in forum Newbie
    Replies: 17
    Last Post: 25th April 2006, 14:57

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.