Starting a selfmade c++ application via Qprocess
-
Hi,
i have a QT widget app. wich starts a c++ application via QProcess.
I wrote this on win10 and now i have to install it on linux/debian9.I changed the path in linux format. Compiled the c++ application on my debian system.
But it won't start.
Here is the code:Constructor:
TemperaturMessung::TemperaturMessung(QWidget *parent) : QMainWindow(parent), ui(new Ui::TemperaturMessung) { ui->setupUi(this); process = new QProcess(this); process->setProcessChannelMode(QProcess::MergedChannels); program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess"; //Tempmess is the c++ aplication wich i want to start fileName = "/Dokumente/Tempmess/Messprotokolle"; ui->speicherOrt->insert(fileName); connect( process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()) ); connect( process, SIGNAL(readyReadStandardError()), this, SLOT(processOutput()) ); connect( process, SIGNAL(started()), ui->startButton, SLOT(hide())); connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), ui->startButton, SLOT(show())); }
Function which starts the process:
void TemperaturMessung::on_startButton_clicked() { //bla bla... QStringList argv; argv << abtastStr << kanalStr << dauerStr<<fileName; process->start(program,argv); process->waitForStarted(); }
Is there anything i have to do with my self compiled programm (The Tempmess thing)?
Thanks for help!
-
Hi and welcome to devnet forum
Looks like you got messed up with path issues.
program = "./Dokumente/Tempmess/Sources/Comreader/Tempmess"; //Tempmess is the c++ aplication wich i want to start fileName = "/Dokumente/Tempmess/Messprotokolle";
The program path is a relative path starting at your current working.
The fileName path is an absolute path. It does not really look as a typical linux path.You can check the currentPath
qDebug() << QDir::currentPath();
From there you can check if the rest ist ok.
Alternatively I would recommend starting with fixed complete absolute path' which typically helps to get an overview.
Also you need to check that your C++ application is starting outside in a terminal. -
@christophator once you solve the issue with the *nix path, you may want to consider using some configuration file (i.e. via QSettings class) to store the path/arguments of the external C++ app to launch so to avoid recompiling your Qt application for Linux, WIndows, etc everytime the path/platform changes
-
@christophator
You should discover why it "did not start" under Linux if you add signal/slot for http://doc.qt.io/qt-5/qprocess.html#errorOccurred. You have done well hooking up the other signals, but you really need that one too, especially for production. -
@koahnig and @Pablo-J-Rogina thank you very much!
I didn't understand how the linux paths work.
I put my c++ application into the current folder of the Qt program and called only the name in the program path.
There it works :)
Now I will get into the QDir and QSettings class to solv it properly. -
@christophator
Linux paths work more-or-less identically to Windows ones, just they use/
instead of\
and don't have a crazy drive letter. -
@christophator
Any path which does not start (very first character) with a/
(Linux) or\
(Windows) is relative. And under Windows be careful with drive letters:D:\fred
is absolute butD:fred
is actually relative, to the current directory on driveD:
, whatever that is. -
@JonB said in Starting a selfmade c++ application via Qprocess:
@christophator
Linux paths work more-or-less identically to Windows ones, just they use/
instead of\
and don't have a crazy drive letter.Not exactly. That seem to reflect the blinker view of linux guys.
Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.
When you are not using linux for daily work, you ask yourself a lot where you can find that stupid device again.
-
@koahnig
Since you have chosen to question what I wrote (as a simplified answer), I shall return the favour by saying "Not exactly" to you!Not exactly. That seem to reflect the blinker view of linux guys.
Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.Nope. That's too simplistic, which is why I didn't mention it! Try each of the following:
dir \c dir /c
They don't produce the same, do they? So it's not fair to say that Windows users can use
/
instead of\
, is it? That seem to reflect the blinker view of Windows guys. :) This is only one example..... -
@JonB said in Starting a selfmade c++ application via Qprocess:
@koahnig
Since you have chosen to question what I wrote (as a simplified answer), I shall return the favour by saying "Not exactly" to you!Not exactly. That seem to reflect the blinker view of linux guys.
Windows does tolerate '/' for a long time already. Me, as a Windows boy, I simply switched to the forward slash long ago.Nope. That's too simplistic, which is why I didn't mention it! Try each of the following:
dir \c dir /c
They don't produce the same, do they? So it's not fair to say that Windows users can use
/
instead of\
, is it? That seem to reflect the blinker view of Windows guys. :) This is only one example.....:D
Not sure, if it is the blinker view of Windows guy or of someone concentrating on a specific topic, the path issue, without mentioning it explicitly. ;) Also, if I am not mistaken, is the backslash used mainly for separation in a long path.BTW Have fun to use in Windows
dir \c
which will not work. Also there the recommendation to use better a forward slash will help. ;)
Anyway I am not interested in specific linux nor windows bashing. Especially the backslash within a path and its special meaning within string drives probably most of the developers nuts. Therefore I am gladly using the forward slash whenever possible.
-
BTW Have fun to use in Windows
dir \c
which will not work.? Of course it "works".
dir \c
means "list the file/directory namedc
in the root folder of the current drive". (If there isn't one, of course it reports File not found, but it's still "working".) OTOH,dir /c
means "list all the files in the current directory on the current drive, passing the/c
switch todir
". Quite different. Which is why I would never use or recommend/
instead of\
for paths in Windows, and I'm surprised you get away with it in practice..... Not Linux vs Windows "bashing" (it was you who used the word "blinker"!), just a heads-up as to it's not robust enough to risk IMHO.....