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. [SOLVED]Communication between QRunnable and main thread

[SOLVED]Communication between QRunnable and main thread

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.8k 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.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    Hi,
    I was looking into the ThreadPool threading option in Qt and just realized that QRunnable doesn't inherit QObject so you can't send signals with it .The only working option I have from "here":http://www.qtcentre.org/threads/37340-Communication-between-QRunnable-and-main-thread is embedding a QObject member and sending the signal with it .

    Is there any other way you have guys of communicating with the GUI thread?

    Thanks.

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      They have another suggestion, a multiple inheritance. Have you tried it.
      @
      class MyRunnable : public QObject, public QRunnable
      {
      ...
      };
      @

      1 Reply Last reply
      0
      • musimbateM Offline
        musimbateM Offline
        musimbate
        wrote on last edited by
        #3

        Thanks for the quick reply,
        I was trying using :
        @

        class MyRunnable : public QRunnable, public QObject
        {
        ...
        };
        

        @

        And it gave those metaobject errors and unresolved symbols.But inheriting QObject first is working .Any Idea why we have to inherit QObject first here?

        Also I how does one go about the postEvent solution suggested at that link.

        Thanks.

        Why join the navy if you can be a pirate?-Steve Jobs

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          [quote author="musimbate" date="1396759690"]Any Idea why we have to inherit QObject first here?
          [/quote]

          One of the "moc limitations":http://qt-project.org/doc/qt-5/moc.html#multiple-inheritance-requires-qobject-to-be-first

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            [quote author="musimbate" date="1396759690"]
            Also I how does one go about the postEvent solution suggested at that link.
            [/quote]

            You can create your own QEvent (or inherited from QEvent) event-object and send it to QObject based object using
            @
            QCoreApplication::postEvent()
            @

            You can postEvent from any object not only QObject based. The receiver of the object must be QObject based.

            More "info":http://qt-project.org/doc/qt-5/eventsandfilters.html#sending-events
            And here is a simple "example":http://qt-project.org/doc/qt-5/qtwidgets-statemachine-pingpong-example.html

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gyll
              wrote on last edited by
              #6

              If you're ready to use Qt only as an OS interface (GUI, sockets, whatever), and clearly separate your app from the Qt interface, i'll publish a multi-threading framework in a week or two. The code works, but i still have to finish the documentation, and i expect this to take me a couple of weeks or so. If you wanna check out what the lib does, the current state of the doc is here: http://www.itgroup.ro/libposif-app-brief.pdf

              1 Reply Last reply
              0
              • musimbateM Offline
                musimbateM Offline
                musimbate
                wrote on last edited by
                #7

                @andreyc:

                Thanks ,the info you provided just answered my questions.

                @gyll :

                Will certainly take the time to look into that lib.Keep it up.

                Why join the navy if you can be a pirate?-Steve Jobs

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gyll
                  wrote on last edited by
                  #8

                  @musimbate: ok, stay subscribed to this forum thread and i'll drop a line here with the details when i'll publish it (it'll prolly be on sourceforge, but ain't sure yet).

                  Cheers!

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gyll
                    wrote on last edited by
                    #9

                    well, it took a while, but here it is: http://libagents.sourceforge.net/

                    1 Reply Last reply
                    2
                    • musimbateM Offline
                      musimbateM Offline
                      musimbate
                      wrote on last edited by
                      #10

                      Looking good.

                      Why join the navy if you can be a pirate?-Steve Jobs

                      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