Results 1 to 7 of 7

Thread: QWidget::exec() and QWidget::show()

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question QWidget::exec() and QWidget::show()

    What is the difference between these two methods? Both display window ...
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget::exec() and QWidget::show()

    exec() blocks the application flow while show() doesn't.
    exec is mainly used for modal dialogs.

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Re: QWidget::exec() and QWidget::show()

    So, then:

    Qt Code:
    1. QWidget::setModal(true);
    2. QWidget::show();
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. QWidget:;exec();
    To copy to clipboard, switch view to plain text mode 

    are identical?
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget::exec() and QWidget::show()

    Not really.
    After calling show() the program flow will continue.
    When you call exec() it will not return until you close the dialog.

    BTW, exec is available only for QDialog.

    Why don't you check the docs about exec and show? They explain it very well.

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QWidget::exec() and QWidget::show()

    Yes, I am checking now, but just final question. So show method initiates its own thread or not?
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QWidget::exec() and QWidget::show()

    no it doesn't.
    Actually as far as I understand, QDialog::exec() does not either - it just intervenes in the vent loop and does not allow new events to get in - but I didn't check QDialogs code, so I am not 100% sure about this.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget::exec() and QWidget::show()

    No, you're right. No thread is started by QDialog::exec nor show(). That would make no sense. The event loop of the parent window is used to process the dialog events.

  8. The following user says thank you to marcel for this useful post:

    MarkoSan (18th October 2007)

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.