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. [Moved] new to Qt development
QtWS25 Last Chance

[Moved] new to Qt development

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 3.7k 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.
  • L Offline
    L Offline
    lgeyer
    wrote on last edited by
    #2

    As you are used to. You can freely mix existing platform-specific code with Qt code (it is C/C++ after all), but you are - of course - not platform independent then.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #3

      Qt provides signals and slots to send messages between objects. You might have a more easy live if you switch to QThread. I'm not 100% sure if it's possible to use signals/slots with native threads (be sure to force the use of queued connections in this case!)

      It is very recommended to read pepps excellent article on "Threads, Events and QObjects":http://developer.qt.nokia.com/wiki/Threads_Events_QObjects in the wiki. It will save you on stepping into common pitfalls using Qt and threads.

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackrussian
        wrote on last edited by
        #4

        Can anyone direct me to sample code showing Qt sending messages to native threads?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #5

          Qt has no means to send messages to native threads. You will have to use the native messaging system the same way as you would without Qt.

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #6

            I guess you could send a Qt signal to a QObject living in a native thread though. And that is basically what you need to do with QThread as well anyway, so it is not that different. Still, I did not try this myself.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #7

              I'm not really sure if that works with signals and slots, as QThread runs its own Qt event loop and for inter-thread signals you will need queued connections. Do the latter work without an event loop on the receiver side?

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #8

                No, you can not receive signals in a slot from a queued connection without a running eventloop on the receiver (slot) side. But again: that is also the case for QThread-based threads, so no big difference there.

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

                  True, but with QThread one gets all the infrastructure for thread safe messaging for free. With native threads one cannot use Qt's signal/slots without further means of making them thread safe. IMHO that's a big difference...

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

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #10

                    I'm not so sure about that. I think you can just spin a QEventLoop from any thread, QThread or not. Sure, QThread has it build in, but I don't think there is much magic involved there. Once you have a running eventloop, you can use slots in the thread, right?

                    I am not saying I'd use this on new code. But if you already have existing threading code that you want to bolt this on to, it should not be impossible to do so.

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

                      [quote author="Andre" date="1317547623"]I'm not so sure about that. I think you can just spin a QEventLoop from any thread, QThread or not. Sure, QThread has it build in, but I don't think there is much magic involved there. Once you have a running eventloop, you can use slots in the thread, right?[/quote]

                      Yes, it should be that way. If a QObject class is created inside a thread that is not a QThread (like the main thread) a pseudo QZhread object is created and it works.

                      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

                      • Login

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