How to communicate to Qt UI application from different process using QProcess



  • Hi,

    I wrote one QT UI application which just has one push button on it.
    I have written one dll using QT, which will be get loaded by third party application. From this dll using QProcess
    I wanted to launch my QT UI application and wanted to send some data to it, whenever my dll exported functions get called by third party app.

    Any idea how can we achieve this..???Will stdin, stdout work in case of QT UI project.?

    Regards
    Ashish



  • You can use IPC, shared memory, local sockets, regular network connections or stdin/stdout. All of those work, all have their own advantages and drawbacks.



  • Does [[Doc:QLocalSocket]] fit your needs? It looks like you need a solution that works on Windows, so QtDBus is out (AFAIK).



  • Hi,

    Thanks for the suggestions, I tried to use QLocalSocket() , created a cient in my dll which is getting launched by third party app, and crated a server in my QtUI application.

    I am not able to connect to server from my dll.
    if returns error code as "QLocalSocket::ServerNotFoundError QAbstractSocket::HostNotFoundError The local socket name was not found."

    However for testing purpose I wrote another sample UI app making it as a client and it is connecting properly.

    Please advice even if I will go for Shared Memory approach , in that case how I will send signal from my dll to UI app to read from shared memory.???

    I am targeting both windows and linux machine.



  • Hi volker,

    As solution proposed by you above doing IPC using stdin and stdout, just for sake of info , I am asking that is it possible to have stdin for UI based App.
    If so would you please give some more idea on how we can achieve this?
    I believe that will be the simplest way to achieve IPC.

    I just wanted to pass two long and one string varaible b/w process.



  • I have used QProcess to launch my qt UI app from dll.
    I can see some functions in QProcess class itself to write data.
    In this case would you please advice how my qt UI app can read the data.



  • "QFile::open() ":/doc/qt-4.8/qfile.html#open-4 has an example for opening stdin.

    If you do not have a running event loop (eg. no Q(Core)Application running) you may run into trouble, dont rely on signals sent out in this case.

    As a last resort you can fall back to standard C++ streaming API or the C file handle API. There's plenty of examples in the interwebs out there, your favorite search engine will be happy to help you here.



  • Thaks a lot Volker for your suggestion. I am going to write shared memory in a plattform dependent manner, but do we have something in qt that will notify another process, to start reading on shared memory. My objective is to use plattform dependent code as least as possible.

    As per best of my knowledge QSystemSemaphore only is visible out of proc.
    How can a separet process on system semaphore , since QWaitCondition doesnt take semaphore.
    I am looking for something similar to HEVENT and waitforsingleobject

    Please advice.



  • Sorry, I never used that stuff in my projects, I could only guess. I would advice to create a minimal test project an play around with the classes.


Log in to reply
 

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