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

Qt and POSIX

Scheduled Pinned Locked Moved General and Desktop
7 Posts 6 Posters 9.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.
  • R Offline
    R Offline
    reetu
    wrote on last edited by
    #1

    I have to develop a Linux daemon that uses the POSIX API to create POSIX threads and POSIX message queues. I would like to use Qt to develop this daemon to take advantage of the Qt libraries and signal/slot mechanism, understanding that the application will not be platform independent. Is it possible to use POSIX API for POSIX threads and message queues with Qt and signals/slots? If so, is there an example of how to do this?

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

      These are three questions:

      1.) can you use POSIX functions inside Qt? Anser is yes, its C/C++ and you can do anything that C/C++ allows.

      2.) Can you use possix threads? Theoretically yes. But, and that is the important thing, you can't use signal/slot across threads without using QtThreads and Qt message loops.

      3.) What do you want to do with POSIX message queues? Inter process communication? Then see answer 1 :-)

      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
        #3

        [quote]2.) Can you use possix threads? Theoretically yes. But, and that is the important thing, you can’t use signal/slot across threads without using QtThreads and Qt message loops.[/quote]

        This is slightly incorrect -- you can mix QThread and native threads, and even use signals from native threads.

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

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

          You can emit Signals from natic threads, but can't use slots inside them :-)
          But I think,. on Linux, QThread objects just encapsulate POSIX threads, don't they?

          But for cross thread signal/slot you need QThreads (at least for the receiving thread) and there a QMessageLoop.

          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
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            Take a look at the "QtService solution":https://qt.gitorious.org/qt-solutions. I have used this successfully in the past.

            I would just use QThread for conveniemce since it just wraps POSIX threads.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • frankcyblogic.deF Offline
              frankcyblogic.deF Offline
              frankcyblogic.de
              wrote on last edited by
              #6

              Just a note: Local sockets would be more portable than POSIX message queues. Also it scales better if you intend to distribute among more machines later. (see: http://doc.qt.nokia.com/4.7-snapshot/qlocalsocket.html

              [EDIT: fixed link, Volker]

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AlterX
                wrote on last edited by
                #7

                I am using native threads emitting signals to Qt main thread and seems to work, but I'm searching for a technique similar to QMetaObject's invokeMethod()

                Is that possible?

                Qt Ambassador
                Real-time cooperative teams: http://www.softairrealfight.net
                Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                https://codereview.qt-project.org/...

                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