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. Sendmessage equivalent function in QT
Forum Update on Monday, May 27th 2025

Sendmessage equivalent function in QT

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

    Hi,
    We have some data comming from library. Now in GUI we have 3 windows and depends on the window handle specified the data get displayed in corresponding window.

    In our existing code we have sendmessage() function in lib to achieve same.

    Now since this function is windows specific and our application is supposed to be platform independent so we want to replace this function by some Qt equivalent function.
    If there is any such function provided by Qt then plz tell.
    Thanks.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      This looks like a good task for "Signals and Slots":http://qt-project.org/doc/qt-5/signalsandslots.html mechanism.

      (Z(:^

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

        actually if i use signal and slot then i have to include that particular window class file in my library and the library becomes dependent on GUi part so i want to avoid this thing.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          [quote author="GAURAV PANT" date="1395748758"]vbgvb[/quote]

          I don't understand that ;)

          (Z(:^

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            [quote author="GAURAV PANT" date="1395748758"]actually if i use signal and slot then i have to include that particular window class file in my library and the library becomes dependent on GUi part so we want to avoid this thing.[/quote]

            Not at all. You can pass a custom window ID as a string, for example, and then check it in every window.

            (Z(:^

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

              @sierzido

              Thanks for your replies. Actually am just a beginner so am not getting how to do this. Can u explain with some example.
              Thanks again. :)

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                I suggest you learn Qt, then, before attempting a rewrite of an existing library and application. This is easy to explain to somebody who knows Qt at least a bit, but hard for a novice.

                In short:
                @
                // your library header
                signals:
                void displayData(const QString &windowId, const Data &myData) const;

                // your library source
                emit displayData("window1", someData);

                // GUI header
                public slots:
                void handleData(const QString &windowId, const Data &myData);

                // GUI source:
                // I assume the signal has been connected somewhere else to this slot
                void MyClass::handleData(const QString &windowId, const Data &myData)
                {
                if (windowId == "window3") {
                // do stuff
                } else {
                // don't display here
                }
                }
                @

                (Z(:^

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

                  Thanks @sierzido. :)

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    Quoting from PM:
                    [quote]Hi Sierzido..
                    Something is going wrong in replying to the post. the page get redirected so
                    m sending u this mail...

                    I am implementing it by the way u suggested..
                    But according to me the the connect call should be in library only.
                    and since its in library so i need to make a GUi object in library which
                    acts as receiver object. I dont want to create Gui object in library.[/quote]

                    No. You only emit the signal in the library, and connect every instance of your window to it. Then, in the slot, you decide whether to display it or not.

                    It may be that I have not understood you well, though, and you do not actually have any instances of windows present by default. In that case, you might need to create some proxy object that will manage window creation for you.

                    PS. It would have been nice if you spelled my nick correctly at least once ;P

                    (Z(:^

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      zeljko
                      wrote on last edited by
                      #10

                      There is solution for multiplatform SendMessage() and PostMessage() if you want to deal with ms style tagMSG struct.
                      1.You must create separate unit with tagMSG struct definitions (so it can be used on non mswin OS-es).
                      2.You must create proper functions eg. SendMessageMP(), PostMessageMP() in that unit
                      3.In both must create custom Qt event and pass tagMSG param.In case of SendMessageMP() you must destroy event (you must wait until sendEvent returns - you send it to Qt by using QCoreApplication::sendEvent), in case of PostMessageMP(), which can be thread safe you just create custom QEvent and post it via QCoreApplication::postEvent().
                      HWND param in both cases is your QWidget.

                      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