Starting an external exe from Qt
-
Hi. I tried using the code from the example of the analog clock in the Qt manual after modifying it a little but it still has a logical error. The plan is that when I click a button, it is supposed to open an exe file. Would someone please show me a snippet of the correct implementation of the code.
-
external processes are started by QProcess.
What did you do? can you show us your code so we can ahve a look at it? -
Refer 'Running a Process' segment under the documentation of "QProcess":http://qt-project.org/doc/qt-4.8/qprocess.html
Have you tried it already? Do you face any issue or error?
-
Thats where I got the snippet but after editing it to suit my app, it does not work. Here's the snippet:
@
QObject *parent;
...
QString program = "C:/programs/bin/snort.exe";
QStringList arguments;
arguments << "-d";QProcess *myProcess = new QProcess(parent); myProcess->start(program, arguments);
@
[Edit: Added @ tags; mlong]
-
Moved to the General forum, as this is nothing for the C++ gurus :)
-
Would you tell us what is the error that you are getting or better send in the full code snippet.
Also try the prefix and suffix your code by @ symbol, so that you get the code in good format
@QObject *parent;
…
QString program = “C:/programs/bin/snort.exe”;
QStringList arguments; arguments << “-d”;QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);@What is parent? It is not allocated with any value and that is being used as the parent for QProcess(). Remember you can pass '0' to QProcess as well or simply don't pass any value, which will default parent pointer to null.
-
A simple way in Windows would be:
(in the slot for the button)
@
void MainWindow::on_pushButton_clicked()
{
system ("start C:\snort\bin\snort.exe");}
@[edit] Added code tags, koahnig
-
[quote author="ommz" date="1339741582"]A simple way in Windows would be:
(in the slot for the button)
@
void MainWindow::on_pushButton_clicked()
{
system ("start C:\snort\bin\snort.exe");}
@
[/quote]Certainly this is a way to do under windows, but it have another implementation for other OS.
QProcess is wrapping the different methods and adds additional comfort. You can redirect" the input and output":http://qt-project.org/doc/qt-4.8/qprocess.html#communicating-via-channels through Qt.
The equivalent to your simple program above would be using "the static execute method. ":http://qt-project.org/doc/qt-4.8/qprocess.html#execute-2
@
void MainWindow::on_pushButton_clicked()
{
QProcess::execute ("start C:\snort\bin\snort.exe");
}
@ -
This post is deleted! -
@ktwalker said in Starting an external exe from Qt:
QProcess as used above in its two different methods start and execute does not work for me with Qt5 on Windows 10. Not sure why. system() works though.
if you need some help why do you not start another post here on forum rather then take a topic that was 7 years ago... a long way back - since then Qt changed a lot...
Start a new topic on this forum, describe your problem as best as you can, provide some more info about your PC and software that you are running (windows GNU/Linux macOs), Qt version.. what are you trying to do and how...
Then we will be able to help.. -
@arsinte_andrei My apologies. I just wanted to let people who see this know there is an issue with it without going into the depth. I did more investigating and determined the problem is related to a drive path issue with my OneDrive. I have posted a new post to the Qt C++ Guru's group. I've also deleted my incorrect post above.