January 4, 2012

Ashish Mittal Ashish Mittal
Hobby Entomologist
109 posts

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

8 replies

January 4, 2012

Volker Volker
Mad Scientist
5250 posts

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.

January 4, 2012

Chris H Chris H
Hobby Entomologist
139 posts

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

January 5, 2012

Ashish Mittal Ashish Mittal
Hobby Entomologist
109 posts

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.

January 5, 2012

Ashish Mittal Ashish Mittal
Hobby Entomologist
109 posts

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.

January 5, 2012

Ashish Mittal Ashish Mittal
Hobby Entomologist
109 posts

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.

January 5, 2012

Volker Volker
Mad Scientist
5250 posts

QFile::open() 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.

January 5, 2012

Ashish Mittal Ashish Mittal
Hobby Entomologist
109 posts

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.

January 5, 2012

Volker Volker
Mad Scientist
5250 posts

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.

 
  ‹‹ How to load data in column based on previous settings.      QFileSystemModel - Adding Custom Columns ››

You must log in to post a reply. Not a member yet? Register here!