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. Mixing pthread and Qt
Forum Updated to NodeBB v4.3 + New Features

Mixing pthread and Qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 10.2k 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.
  • F Offline
    F Offline
    florent.revelut
    wrote on last edited by
    #1

    We have a project which will require to link together 2 pieces of code :

    • the core program, working with Qt (multithreaded with QThread, owning the main thread)
    • one multithreaded library (developped internally), based on STL/pthread

    At some point we'll have to handle asynchronism between these libraries.

    Any point we need to pay good attention to ?

    I was especially thinking:

    • are signals/slots working from a standard thread (not QThread) ?
    • can we create a QObject from any thread ?
    • would recursive semaphore work ?

    We'll spike a few of these issues, but any feedback or pointer would be greatly appreciated !

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      In general, it's perfectly safe to mix QThreads and native threads (QThread is implemented "on top" of native threads).

      bq. # are signals/slots working from a standard thread (not QThread) ?

      Yes, but queued connections will require that the receiver is actually living in a QThread with a running event loop.

      bq. # can we create a QObject from any thread ?

      Yes.

      bq. # would recursive semaphore work ?

      What does that mean? :)

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Franzk
        wrote on last edited by
        #3

        [quote author="peppe" date="1292974148"]bq. # are signals/slots working from a standard thread (not QThread) ?

        Yes, but queued connections will require that the receiver is actually living in a QThread with a running event loop.[/quote]
        I don't think you necessarily need to have a QThread with running event loop. The QThread has nothing to do with the objects inside them. It is probably perfectly reasonable to implement your own native thread function and start an event loop in it to have queued connections working. However, it would just be reinventing the wheel.

        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          If you create QObjects inside a non QThread object (like also main thread :-) ) you get a pseudo QThread object which is used for the thread affinity of your object. If you spin an event loop there, signals/slots definitely work there.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on last edited by
            #5

            [quote author="Franzk" date="1293004844"][quote author="peppe" date="1292974148"]bq. # are signals/slots working from a standard thread (not QThread) ?

            Yes, but queued connections will require that the receiver is actually living in a QThread with a running event loop.[/quote]
            I don't think you necessarily need to have a QThread with running event loop. The QThread has nothing to do with the objects inside them. It is probably perfectly reasonable to implement your own native thread function and start an event loop in it to have queued connections working. However, it would just be reinventing the wheel.

            [/quote]

            Start it how? QEventLoop? All in all it may work, it's just a simple test -- list time I tried, it didn't, so perhaps something has changed in Qt. Even better, I'd say! :-)

            Software Engineer
            KDAB (UK) Ltd., a KDAB Group company

            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