Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Threading and the main QT event loop.
Forum Updated to NodeBB v4.3 + New Features

Threading and the main QT event loop.

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 815 Views 2 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.
  • R Offline
    R Offline
    RobM
    wrote on last edited by
    #1

    I was hoping someone might give me some insight into how to better handle a situation I have. There are many time in this application where an event goes something like this:

    • User clicks button to do something

    • Signal is sent to business logic to ask threaded application to do that thing

    • Thing takes application x amount of time to do

    • Application responds with thing

    While x amount of time passes the main event thread is locked. Currently, the application deals with this scenario by creating a busy wait and while waiting calls the QCoreApplication::processEvents(); which seems wrong. Can someone point me at some documentation for how other QT developers deal with situations like this? Perhaps they crafty use a mutex or simply ask the application to sleep? Perhaps a busy wait loop is the best option?

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi,

      What is your exact architecture ?

      If you have data exchange between two different applications you might want to consider using a model for the data and add a read-only entry to it while the creation is in progress with a status text explaining that. Then once the data is arrived make it read/write and show the actual data.

      There should be no need to freeze your UI for that. If you need to actually wait for something without your users being able to interact with your application then a QProgressDialog will be a better solution.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      2
      • R RobM

        I was hoping someone might give me some insight into how to better handle a situation I have. There are many time in this application where an event goes something like this:

        • User clicks button to do something

        • Signal is sent to business logic to ask threaded application to do that thing

        • Thing takes application x amount of time to do

        • Application responds with thing

        While x amount of time passes the main event thread is locked. Currently, the application deals with this scenario by creating a busy wait and while waiting calls the QCoreApplication::processEvents(); which seems wrong. Can someone point me at some documentation for how other QT developers deal with situations like this? Perhaps they crafty use a mutex or simply ask the application to sleep? Perhaps a busy wait loop is the best option?

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #2

        @RobM
        The intention of the Qt paradigm is that there ought be no "waiting". Since your business logic runs in its own thread it just sends a signal when it is "done" or "has something to say". I don't know why you busy wait + processEvents(). Why does your UI have to "wait" for anything?

        R 1 Reply Last reply
        1
        • JonBJ JonB

          @RobM
          The intention of the Qt paradigm is that there ought be no "waiting". Since your business logic runs in its own thread it just sends a signal when it is "done" or "has something to say". I don't know why you busy wait + processEvents(). Why does your UI have to "wait" for anything?

          R Offline
          R Offline
          RobM
          wrote on last edited by
          #3

          @JonB Well, it depends on the instance but in general it's because the secondary application is the thing that is providing the real data that can be manipulated by the user. So for instance, let's say the user decides they want to create a job. The main application needs to ask the secondary application to first create the job (it handles remember the job exists) and then it feeds the primary application that job. So the user must wait for the job before they can start altering it or at least, that' s a simple way of handling it. Perhaps what should be done is to keep a copy of the job on the main application and then synchronize the data when it needs to be saved. Which may end up happening but in the meantime I was thinking perhaps the main application would be better served by a mutex or an atomic rather than using a busy wait loop to wait for the secondary application to finish processing.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            What is your exact architecture ?

            If you have data exchange between two different applications you might want to consider using a model for the data and add a read-only entry to it while the creation is in progress with a status text explaining that. Then once the data is arrived make it read/write and show the actual data.

            There should be no need to freeze your UI for that. If you need to actually wait for something without your users being able to interact with your application then a QProgressDialog will be a better solution.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            R 1 Reply Last reply
            2
            • SGaistS SGaist

              Hi,

              What is your exact architecture ?

              If you have data exchange between two different applications you might want to consider using a model for the data and add a read-only entry to it while the creation is in progress with a status text explaining that. Then once the data is arrived make it read/write and show the actual data.

              There should be no need to freeze your UI for that. If you need to actually wait for something without your users being able to interact with your application then a QProgressDialog will be a better solution.

              R Offline
              R Offline
              RobM
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0

              • Login

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