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. How to implement a user-defined message?

How to implement a user-defined message?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • C Offline
    C Offline
    chcw
    wrote on last edited by
    #1

    Hi,

    I am using Qt 4.8.3 to implement a Windows desktop application. Now I need to implement a user-defined message. Then in a thread of the application, I need to send this message the main Qt Window and wait until the message is processed by the main Window, just like the SendMessage function in Windows SDK. How to do this?

    Currently I can implement the feature like PostMessage, but what I need is like SendMessage, to wait until the message is processed.

    If there is a sample, then that will be great!

    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      Window Messages are a Microsoft Windows thingy. With Qt you generally would not do this with "native" Window Messages. It's unusual and it would not be portable at all! Instead you use "Signals and Slots":http://qt-project.org/doc/qt-4.8/signalsandslots.html.

      Note: What you want here is a "BlockingQueuedConnection":http://qt-project.org/doc/qt-4.8/qt.html#ConnectionType-enum ;-)

      Example:
      http://pastie.org/9207247

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chcw
        wrote on last edited by
        #3

        So if I understand correctly, here signal just works like a message in Windows, and BlockingQueuedConnection works like a message queue that is synchronous.

        Thanks

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          [quote author="chcw" date="1400972448"]So if I understand correctly, here signal just works like a message in Windows[/quote]

          Well, in a way, yes.

          But while Window Messages are transmitted between Windows and they are specific to the Windows operating system, Signals are transmitted between Qt Objects and they are cross-platform. Also a Signal can contain arbitrary parameters, like a function call. It's actually more like a fully-fledged RPC.

          Since the concept of "Signals and Slots":http://qt-project.org/doc/qt-4.8/signalsandslots.html is so important for Qt, I really recommend you carefully read the Qt documentation about it!

          [quote author="chcw" date="1400972448"]and BlockingQueuedConnection works like a message queue that is synchronous.[/quote]

          Well, with a standard (direct) connection, the Slot will be executed immediately and in the same thread that emitted the Signal. But with a queued connection, the Slot will be executed in the thread to which the receiver object belongs. So if the "background" thread sends a queued signal to the "main" dialog (which belongs to the "main" thread), then the Slot is executed in the context of the "main" thread. Note, however, that using queued connections requires that the receiving thread runs an event loop - similar to a "message pump" in native Windows applications. Last but not least, a blocking queued connection works exactly like a queued one, except that the thread which emits the signal will be blocked until the receiving thread has actually processed the signal.

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          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