QT Inter Process Communication between softwares
-
I have a application software developed in qt with my side in windows. What i want to do is, i want to control another 3rd party application software like Microsoft power-point. The control functions i need is simple and for example
- To change the slide when i press a button in my qt app.
- Zoom the slide area when i press another button.
I read about IPC accessibility in windows and i don't which one should we use and how to use to transfer functions between qt and power-point
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx
Hope you guys will help me to figure out this problem. Thanks in advance
-
Hi,
if you want control a 3rdparty software you have to verify if and what kind of IPC protocol the software supports.
I mean that, if you want control PowerPoint, you have to read in the PowerPoint documentation if it can be controlled via IPC (IIRC MS Office provide a developer library) -
An easy way to control Microsoft Office applications "remotely" is through OLE Automation.
Here's an example (in C, but should be easy to port to C++) how to open/close Excel: OLE Automation and here's more details and examples in the form of Q&A.
Also, Qt provides QAxObject to ease the COM stuff involved with the above.
-
After some google search I think we can create keyboard events, since Powerpoint have some keyboard shortcuts...
So now i want to develop my Qt app with a button.. on pressing that some keyboard events should generate and Powerpoint will accept that..
But how highlighting two apps at the same time... ?
Whether Powerpoint will get that keyboard events? -
You can't. Only one app can have focus, but that's really not a good idea even if it was possible. What would happen if something changed the currently focused app or moves a mouse while your program runs?
Automation is your best bet here and it's easier than it might seem.
Here's a little demo I did some time ago that opens PowerPoint, starts a slideshow, switches every slide after 3s and then closes.#include <Windows.h> #include <QCoreApplication> #include <QAxObject> #include <QThread> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString pptFile = "C:/some_file.pptx"; CoInitialize(NULL); { QAxObject pp("PowerPoint.Application", nullptr); auto presentations = pp.querySubObject("Presentations"); auto presentation = presentations->querySubObject("Open(QString)", pptFile); auto slides = presentation->querySubObject("Slides"); auto sliseshowsettings = presentation->querySubObject("SlideShowSettings"); sliseshowsettings->dynamicCall("Run()"); auto slideshowwindow = presentation->querySubObject("SlideShowWindow"); auto slideshowview = slideshowwindow->querySubObject("View"); int numSlides = slides->property("Count").toInt(); for(int i = 1; i < numSlides; ++i) { QThread::currentThread()->sleep(3); slideshowview->dynamicCall("Next()"); } QThread::currentThread()->sleep(3); pp.dynamicCall("Quit()"); } CoUninitialize(); }
-
But virtual keyboard in windows works..
We can create keyboard events with mouse clicks which will get accepted by the software just focused back with the help of this on screen keyboard..
In short i think i need to develop one like virtual keyboard with qtbuttons.void MainWindow::on_pushButton_clicked() { keybd_event(VK_SPACE, 0x20, 0, 0); keybd_event(VK_SPACE, 0x20, KEYEVENTF_KEYUP, 0); }
But it doesn't doing anything ...
Please help me to figure out this -
When you click a button the focus is on that button and the active app is the one with the button. If you create a keyboard event at that time it will be sent to the active app (the one with the button) and then to the button itself. It goes nowhere near PowerPoint or any other app this way.
If you wanted to pass the keyboard messages to another app in the background you would have to get a handle to it (e.g. using FindWindow and then post keyboard messages directly to it using PostMessage. This has some serious limitations and side effects though, as described well here by one of the MS guys.
As I said earlier - it's a very bumpy road to do it this way and extremely error prone.
I'd really reconsider automation. -
Automation is good...
But my ultimate aim is to develop a qt app which responds to hand gestures using image processing. And that section is ok.
I want to control powerpoint using my hand gestures.
I think virtual keyboard is capable of sending keyboard signals to another application.
So how to transfer the control signals to Powerpoint from my qt app.??