i'm trying to set up a GUI with Qt for an existing application which is meant to be run in the windows commandline. It's not just running the app with the
system()
command, but i need to interact with the existing application via command line.
The system()
command blocks the GUI when i start the existing executable. How can i run this executable in the background and trigger some inputs via my own GUI-Elements such as a button?
I want to simplify the usage of this command line tool for some of my colleagues.
It would be mainly used on windows.
Thanks for your help.
Out of curiosity, I played around with
QProcess
.I'm really impressed how easy and straight forward everything works (remembering with horror how difficult it was when we did it in the past without Qt).
Thus, I can provide my little rather MCVE for demonstration.
First I made a simple console application
testQProcessIOChild.cc
:I did this to have something which provides:
Second I made the Qt GUI application
testQProcessIO.cc
as wrapper:I compiled and tested this with VS2013 and Qt 5.9.2 on Windows 10 (64 bit).
To illustrate the test session I wrote a QMake project afterwards
testQProcessIO.pro
:and compiled and tested on cygwin again:
Snapshots of my test sessions:
I found a solution for my needs and can do what i want to do.. Actually i'm a bit disappointed. I thought it would be something more complex.
First i have to say it's an QtQuick Application .. Maybe i should have said that earlier.
I simply outsourced the process functions to another class. This class is passed to QML via the
qmlRegisterType<>()
function. I connected some signals from the process (QProcess
) to slots in my own class and wrote my own functions to handle reading/writing data from and to the console application. With the QML-onClicked
events i can pass my parameters and strings to the console app. And with some application logic i can handle the in/out requests and timings.WrapperClass.h
WrapperClass.cpp
Main.cpp
With registering the Cpp-Class to QML i'm able to trigger the read/write functions via Click-Events from QML-
MouseArea
orButton
.