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. QThread Blocking
QtWS25 Last Chance

QThread Blocking

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k Views
  • 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.
  • qt27Q Offline
    qt27Q Offline
    qt27
    wrote on last edited by
    #1

    I have a QMainWindow and want to use macros/scripts to automate things offered in the QMainWindow application. Among other things, this application uses a library that allows collecting data (in a thread) which also has a callback function when the data gathering is done. So it's something like this:

    class MyWindow : public QMainWindow()
    {
    RunMacro(Macro macro);
    static void CALLBACK MyCallback();
    private slots:
    OnGatherData();
    }

    The macro could be something like this:
    GatherData
    WaitForDataGatheringDone

    The above are executed by RunMacro. What I did to not block the GUI is creating a threat, passing it a pointer to MyWindow and in that thread I call RunMacro. My expectation was, that because RunMacro is called by a different thread MyWindow would not block. However, it does seem to block because my callback function to indicate that the data gathering is done gets never called. If that is indeed the case, then how would I solve it that I still can get that callback and not block MyWindow?

    kshegunovK 1 Reply Last reply
    0
    • qt27Q qt27

      I have a QMainWindow and want to use macros/scripts to automate things offered in the QMainWindow application. Among other things, this application uses a library that allows collecting data (in a thread) which also has a callback function when the data gathering is done. So it's something like this:

      class MyWindow : public QMainWindow()
      {
      RunMacro(Macro macro);
      static void CALLBACK MyCallback();
      private slots:
      OnGatherData();
      }

      The macro could be something like this:
      GatherData
      WaitForDataGatheringDone

      The above are executed by RunMacro. What I did to not block the GUI is creating a threat, passing it a pointer to MyWindow and in that thread I call RunMacro. My expectation was, that because RunMacro is called by a different thread MyWindow would not block. However, it does seem to block because my callback function to indicate that the data gathering is done gets never called. If that is indeed the case, then how would I solve it that I still can get that callback and not block MyWindow?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @qt27
      Hi,
      This whole procedure sounds very suspicious and unnecessary, not to mention it probably is a disaster waiting to happen. What's the problem with connecting a few signals to some slots instead?

      The above are executed by RunMacro. What I did to not block the GUI is creating a threat, passing it a pointer to MyWindow and in that thread I call RunMacro.

      You just basically described what you should not do. For one the GUI classes are not even reentrant, not to mention thread-safe and while one could probably make an argument for synchronizing a few own methods it is ultimately unneeded.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • qt27Q Offline
        qt27Q Offline
        qt27
        wrote on last edited by
        #3

        @qt27, thanks for the feedback. So the only other option I see then is creating a thread that sends signals for each macro/script step to the MyWindow application. I was kind of hoping to avoid this as it means creating a lot of pretty much duplicate signals (one from the GUI which gets arguments from an input window and one for the script/macro which gets arguments from the script/macro).

        kshegunovK 1 Reply Last reply
        0
        • qt27Q qt27

          @qt27, thanks for the feedback. So the only other option I see then is creating a thread that sends signals for each macro/script step to the MyWindow application. I was kind of hoping to avoid this as it means creating a lot of pretty much duplicate signals (one from the GUI which gets arguments from an input window and one for the script/macro which gets arguments from the script/macro).

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @qt27

          So the only other option I see then is creating a thread that sends signals for each macro/script step to the MyWindow application.

          Rather a worker object that runs inside a separate thread, but yes, that approach sounds much better to me.

          I was kind of hoping to avoid this as it means creating a lot of pretty much duplicate signals (one from the GUI which gets arguments from an input window and one for the script/macro which gets arguments from the script/macro).

          I wouldn't call two signals-slot connections "a lot" and you skip the whole manual thread synchronization fiasco ... I should think this is good, isn't it?

          Kind regards.

          Read and abide by the Qt Code of Conduct

          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