Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When to use EventLoop exec and QApp exe
Forum Updated to NodeBB v4.3 + New Features

When to use EventLoop exec and QApp exe

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Pradeep P NP Offline
    Pradeep P NP Offline
    Pradeep P N
    wrote on last edited by
    #1

    QApplication has exec function which starts the event loop. Also I can start the even loop using QEventLoop exec function. when should I used the QApp exec ? and when should i used the QEventLoop exec ?. Assume I have started the eventloop through QApp in main.cpp and inside the constructor I call exec through QEventLoop. What is the use starting another even loop constructor or somewhere else ?

    Pradeep Nimbalkar.
    Upvote the answer(s) that helped you to solve the issue...
    Keep code clean.

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      There's rarely need for an explicit creation of your own QEventLoop instance.
      Most of the places you would need it are covered by a convenience exec() method on a relevant class that will create and run one for you eg.

      QApplication::exec - (almost) every Qt app needs QApplication instance and an event loop so this is just to type less.

      QThread::exec - usually you want a thread to run its own event loop so the run method of QThread will call this exec and run one for you.

      QDialog::exec - its often convenient to run a dialog in a separate loop that returns a value (accepted/rejected) so this will create one and run for you.

      Usually the only place to use QEventLoop directly is when you are not covered by these scenarios and need a fine grained control in your local loop eg. use QEventLoop::exec parameters to discard specific events in that loop or create your own class that has this loop-return code pattern, create a local loop in a dynamically loaded library etc. but these are very rare occasions.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved