0

I have a tool to run main application - both are QApplications. in the tool I start main app as QProcess::startDetached("myapp.exe", QStringList() << "-arg1" << "-arg2", "C:/myFolder/");

then the tool finishes its work and the main app is still working.

I can start the tool again, and send commands via QSharedMemory. But if main app has opened modal dialog, it cannot handle new commands.

I need to determine from the tool that main app is busy with modal dialog and return some kind of error.

could anyone please tell me what is the simplest way to do it.

I have two ideas, but they really don't know if any of them will work:

  1. use QApplication::activeModalWidget(), but how to get QApplication* of main app from the tool?

  2. put information that the main app is busy in shared memory, and the tool'll check it before closing itself. - I'm not sure that the main app'll be able to save something in shared memory while it's busy with modal dialog.

Illia Levandovskyi
  • 1,228
  • 1
  • 11
  • 20

1 Answers1

2

Personally, I'd use QLocalServer in the main app and QLocalSocket in the tool.

When the main app starts, it starts the local server running, allowing the tool to connect to it and communicate as required.

At its most basic level, if the tool can connect to the server, you know the main application is running. However I would recommend using this IPC mechanism over QSharedMemory.

Done properly, the tool can happily disconnect and reconnect without issue.

Qt provides an example of how to use QLocalServer with QLocalSocket

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85