Sendmessage equivalent function in QT



  • 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.


  • Moderators

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



  • 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.


  • Moderators

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

    I don't understand that ;)


  • Moderators

    [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.



  • @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. :)


  • Moderators

    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
    }
    }
    @



  • Thanks @sierzido. :)


  • Moderators

    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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.