QProcess sample
-
Trying to compile test sample from official Qt documentation:
#include <QCoreApplication> #include <QProcess> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QProcess process; // process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args) // { // args->flags |= CREATE_NEW_CONSOLE; // args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES; // args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE; // args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED // | FOREGROUND_INTENSITY; // }); // process.start("C:\\Windows\\System32\\cmd.exe", QStringList() << "/k" << "title" << "The Child Process"); return a.exec(); }
Gettings errors below.
Using Ubuntu Jammy Fish, Qt 6.2.4, gcc04:03:25: Running steps for project untitled...
04:03:25: Configuration unchanged, skipping qmake step.
04:03:25: Starting: "/usr/bin/make" -j8
g++ -c -pipe -g -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_CORE_LIB -I../untitled -I. -I../Qt/6.2.4/gcc_64/include -I../Qt/6.2.4/gcc_64/include/QtCore -I. -I../Qt/6.2.4/gcc_64/mkspecs/linux-g++ -o main.o ../untitled/main.cpp
../untitled/main.cpp: In function ‘int main(int, char**)’:
../untitled/main.cpp:11:13: error: ‘class QProcess’ has no member named ‘setCreateProcessArgumentsModifier’
11 | process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments args)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../untitled/main.cpp:11:51: error: ‘QProcess::CreateProcessArguments’ has not been declared
11 | process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments args)
| ^~~~~~~~
../untitled/main.cpp: In lambda function:
../untitled/main.cpp:13:57: error: request for member ‘flags’ in ‘ args’, which is of non-class type ‘int’
13 | args->flags |= CREATE_NEW_CONSOLE;
| ^~~~~
../untitled/main.cpp:13:66: error: ‘CREATE_NEW_CONSOLE’ was not declared in this scope
13 | args->flags |= CREATE_NEW_CONSOLE;
| ^~~~~~~~~~~~~~~~~~
../untitled/main.cpp:14:57: error: request for member ‘startupInfo’ in ‘ args’, which is of non-class type ‘int’
14 | args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
| ^~~~~~~~~~~
../untitled/main.cpp:14:82: error: ‘STARTF_USESTDHANDLES’ was not declared in this scope
14 | args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
| ^~~~~~~~~~~~~~~~~~~~
../untitled/main.cpp:15:57: error: request for member ‘startupInfo’ in ‘* args’, which is of non-class type ‘int’
15 | args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE;
| ^~~~~~~~~~~
../untitled/main.cpp:15:81: error: ‘STARTF_USEFILLATTRIBUTE’ was not declared in this scope
15 | args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE;
| ^~~~~~~~~~~~~~~~~~~~~~~
../untitled/main.cpp:16:57: error: request for member ‘startupInfo’ in ‘* args’, which is of non-class type ‘int’
16 | args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
| ^~~~~~~~~~~
../untitled/main.cpp:16:88: error: ‘BACKGROUND_BLUE’ was not declared in this scope
16 | args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
| ^~~~~~~~~~~~~~~
../untitled/main.cpp:16:106: error: ‘FOREGROUND_RED’ was not declared in this scope
16 | args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
| ^~~~~~~~~~~~~~
../untitled/main.cpp:17:90: error: ‘FOREGROUND_INTENSITY’ was not declared in this scope
17 | | FOREGROUND_INTENSITY;
| ^~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:981: main.o] Error 1
04:03:26: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled (kit: Desktop Qt 6.2.4 GCC 64bit)
When executing step "Make"
04:03:26: Elapsed time: 00:01. -
Hi,
Aren't you trying to build on Linux a Windows specific example ?
-
Trying to compile test sample from official Qt documentation:
#include <QCoreApplication> #include <QProcess> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QProcess process; // process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args) // { // args->flags |= CREATE_NEW_CONSOLE; // args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES; // args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE; // args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED // | FOREGROUND_INTENSITY; // }); // process.start("C:\\Windows\\System32\\cmd.exe", QStringList() << "/k" << "title" << "The Child Process"); return a.exec(); }
Gettings errors below.
Using Ubuntu Jammy Fish, Qt 6.2.4, gcc04:03:25: Running steps for project untitled...
04:03:25: Configuration unchanged, skipping qmake step.
04:03:25: Starting: "/usr/bin/make" -j8
g++ -c -pipe -g -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_CORE_LIB -I../untitled -I. -I../Qt/6.2.4/gcc_64/include -I../Qt/6.2.4/gcc_64/include/QtCore -I. -I../Qt/6.2.4/gcc_64/mkspecs/linux-g++ -o main.o ../untitled/main.cpp
../untitled/main.cpp: In function ‘int main(int, char**)’:
../untitled/main.cpp:11:13: error: ‘class QProcess’ has no member named ‘setCreateProcessArgumentsModifier’
11 | process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments args)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../untitled/main.cpp:11:51: error: ‘QProcess::CreateProcessArguments’ has not been declared
11 | process.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments args)
| ^~~~~~~~
../untitled/main.cpp: In lambda function:
../untitled/main.cpp:13:57: error: request for member ‘flags’ in ‘ args’, which is of non-class type ‘int’
13 | args->flags |= CREATE_NEW_CONSOLE;
| ^~~~~
../untitled/main.cpp:13:66: error: ‘CREATE_NEW_CONSOLE’ was not declared in this scope
13 | args->flags |= CREATE_NEW_CONSOLE;
| ^~~~~~~~~~~~~~~~~~
../untitled/main.cpp:14:57: error: request for member ‘startupInfo’ in ‘ args’, which is of non-class type ‘int’
14 | args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
| ^~~~~~~~~~~
../untitled/main.cpp:14:82: error: ‘STARTF_USESTDHANDLES’ was not declared in this scope
14 | args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
| ^~~~~~~~~~~~~~~~~~~~
../untitled/main.cpp:15:57: error: request for member ‘startupInfo’ in ‘* args’, which is of non-class type ‘int’
15 | args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE;
| ^~~~~~~~~~~
../untitled/main.cpp:15:81: error: ‘STARTF_USEFILLATTRIBUTE’ was not declared in this scope
15 | args->startupInfo->dwFlags |= STARTF_USEFILLATTRIBUTE;
| ^~~~~~~~~~~~~~~~~~~~~~~
../untitled/main.cpp:16:57: error: request for member ‘startupInfo’ in ‘* args’, which is of non-class type ‘int’
16 | args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
| ^~~~~~~~~~~
../untitled/main.cpp:16:88: error: ‘BACKGROUND_BLUE’ was not declared in this scope
16 | args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
| ^~~~~~~~~~~~~~~
../untitled/main.cpp:16:106: error: ‘FOREGROUND_RED’ was not declared in this scope
16 | args->startupInfo->dwFillAttribute = BACKGROUND_BLUE | FOREGROUND_RED
| ^~~~~~~~~~~~~~
../untitled/main.cpp:17:90: error: ‘FOREGROUND_INTENSITY’ was not declared in this scope
17 | | FOREGROUND_INTENSITY;
| ^~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:981: main.o] Error 1
04:03:26: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled (kit: Desktop Qt 6.2.4 GCC 64bit)
When executing step "Make"
04:03:26: Elapsed time: 00:01.Read here
As @SGaist already said, this code will only work on Windows. I can imagine, it is also mentioned in the example.
-
Read here
As @SGaist already said, this code will only work on Windows. I can imagine, it is also mentioned in the example.
-
@Pl45m4 can you pls share example, it got to be much easier for me
anything to manage terminal inside gui@JohnLocke said in QProcess sample:
can you pls share example
What example?!
anything to manage terminal inside gui
"Terminal inside GUI"? Can you explain what you want to achieve?
-
@JohnLocke said in QProcess sample:
can you pls share example
What example?!
anything to manage terminal inside gui
"Terminal inside GUI"? Can you explain what you want to achieve?
The original code snippet would open an independent Windows CMD, possibly set some custom colours, change its window title, and then leave it waiting for further user input. The equivalent in the Linux world might go something like this:
#include <QCoreApplication> #include <QProcess> #include <QTimer> int main(int argc, char **argv) { QCoreApplication app(argc, argv); QProcess process; process.start("/usr/bin/xterm", QStringList() << "-T" << "The Child Process" << "-fg" << "red" << "-bg" << "blue" ); QTimer::singleShot(10000, &app, &QCoreApplication::quit); return app.exec(); }
-
The original code snippet would open an independent Windows CMD, possibly set some custom colours, change its window title, and then leave it waiting for further user input. The equivalent in the Linux world might go something like this:
#include <QCoreApplication> #include <QProcess> #include <QTimer> int main(int argc, char **argv) { QCoreApplication app(argc, argv); QProcess process; process.start("/usr/bin/xterm", QStringList() << "-T" << "The Child Process" << "-fg" << "red" << "-bg" << "blue" ); QTimer::singleShot(10000, &app, &QCoreApplication::quit); return app.exec(); }
-
@ChrisW67
Good stuff. I assume this causes the terminal to exit after 10 seconds when the parent process exits? If so, the OP may want to usestartDetached()
instead of juststart()
? -
@JonB I just put the timer there so that the example would exit because there is no GUI other than the xterm GUI. The original code snippet would require a Ctrl-C or other forced termination. It's just an example, not a useful program.
-
@ChrisW67 how to be able to write something inside xterm?
i've tried qDebug, but it sends to gnome-terminal (standard presentation) -
@ChrisW67 how to be able to write something inside xterm?
i've tried qDebug, but it sends to gnome-terminal (standard presentation)@JohnLocke said in QProcess sample:
how to be able to write something inside xterm?
Using QProcess::write. There is even an example in the documentation.
-
@ChrisW67 how to be able to write something inside xterm?
i've tried qDebug, but it sends to gnome-terminal (standard presentation)