QString replace %U
-
@jsulm Click QAction QProcess do not start, copy qDebug() content to terminal can run.
QString sExec = readSettings(desktop, "Desktop Entry", "Exec"); sExec.replace(QString("%U"), filepath, Qt::CaseInsensitive); sExec.replace(QString("%F"), filepath, Qt::CaseInsensitive); connect(action, &QAction::triggered, [=](){ QProcess *process = new QProcess; process->setWorkingDirectory(path); qDebug() << sExec; //process->start(sExec); process->setProgram(sExec); process->startDetached(); });
@sonichy
IssExec
set to the correct full path to the executable? What do you think yourprocess->setWorkingDirectory(path);
achieves? Because if you think it is used to locate the executable to run, it is not.The
bool QProcess::startDetached(qint64 *pid = nullptr)
overload you are now using has a return value. Do you think you ought look at that if you are having a problem? -
@sonichy said in QString replace %U:
This is new problem after modify the code
Fair enough, I did say you would have see whether it causes problems. This raises a nasty question of what Qt requires the scope/lifetime of the process used in
QProcess::startDetached()
to be: it cannot be "forever", because we know detached processes survive even exiting the parent program. Maybe it requires it to exist till at leaststarted()
signal has been received, I don't know.Actually, hang on! The overload of
startDetached
you are using is bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr). That isstatic
!Soooo:
-
process->setWorkingDirectory(sPath);
has no effect (the method signature above takes an optional parameter for the working directory instead). -
Your
QProcess *process = new QProcess;
is not used. -
You can write
QProcess::startDetached(sExec, QStringList());
instead, noQProcess
instance needed, and no leaking. -
Given this I find it hard to believe that changing
QProcess *process
toQProcess process
can have any effect....
@JonB Two method:
bool QProcess::startDetached(qint64 *pid = nullptr)[static] bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr)
And static do not start either.
QProcess::startDetached(sExec, QStringList(), path);
-
-
@JonB Two method:
bool QProcess::startDetached(qint64 *pid = nullptr)[static] bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr)
And static do not start either.
QProcess::startDetached(sExec, QStringList(), path);
-
@JonB Two method:
bool QProcess::startDetached(qint64 *pid = nullptr)[static] bool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr)
And static do not start either.
QProcess::startDetached(sExec, QStringList(), path);
-
@sonichy
Then I do not see that anything you have had so far can have succeeded, but it's most unclear from your comments what that case is.As per my previous, could you please show what your
qDebug() << sExec;
is outputting, instead of making us guess? -
@sonichy said in QString replace %U:
deepin-draw
This is a relative path. Pass whole path, so it can actually be found...
And please add error handling... -
@sonichy said in QString replace %U:
@JonB deepin-draw "/home/sonichy/Desktop/KuGou.png"
I previously wrote:
Is
sExec
set to the correct full path to the executable? What do you think yourprocess->setWorkingDirectory(path);
achieves? Because if you think it is used to locate the executable to run, it is not. -
@sonichy said in QString replace %U:
@JonB deepin-draw "/home/sonichy/Desktop/KuGou.png"
I previously wrote:
Is
sExec
set to the correct full path to the executable? What do you think yourprocess->setWorkingDirectory(path);
achieves? Because if you think it is used to locate the executable to run, it is not. -
@jsulm
It would be nice if questioners answered questions and acted on recommendations before just reposting that something does not work. Makes we wonder sometimes why we bother. If I ask a question and somebody gives some suggestions I act on those carefully before asking again. But that's another topic... :) -
@sonichy said in QString replace %U:
@JonB deepin-draw "/home/sonichy/Desktop/KuGou.png"
I previously wrote:
Is
sExec
set to the correct full path to the executable? What do you think yourprocess->setWorkingDirectory(path);
achieves? Because if you think it is used to locate the executable to run, it is not.@JonB
The Linux desktop file installed by root(deb) do not contain Path.
And absolute exe path do not work either:/usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
Error handle
connect(action, &QAction::triggered, [=](){ QProcess *process = new QProcess; //process->setWorkingDirectory(path); qDebug() << sExec; //process->start(sExec); //crash process->setProgram(sExec); connect(process, &QProcess::readyReadStandardError, [=](){ qDebug() << process->errorString(); //nothing }); bool b = process->startDetached(); qDebug() << b; //false //QProcess::startDetached(sExec, QStringList(), path); });
-
@JonB
The Linux desktop file installed by root(deb) do not contain Path.
And absolute exe path do not work either:/usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
Error handle
connect(action, &QAction::triggered, [=](){ QProcess *process = new QProcess; //process->setWorkingDirectory(path); qDebug() << sExec; //process->start(sExec); //crash process->setProgram(sExec); connect(process, &QProcess::readyReadStandardError, [=](){ qDebug() << process->errorString(); //nothing }); bool b = process->startDetached(); qDebug() << b; //false //QProcess::startDetached(sExec, QStringList(), path); });
-
If you mean that
qDebug() << sExec;
outputs/usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
then that is your problem. That line is not a program/executable, is it? The first word is the executable and the second word is an argument (and when passed as an argument it should not then have"
s around it). And if that is the case it would have saved a lot of time if you had shown this from the start. -
qDebug() << process->errorString(); //nothing
This is not what you are supposed to output if you receive some data on standard error, you are supposed to print the data you receive.
-
-
@JonB
The Linux desktop file installed by root(deb) do not contain Path.
And absolute exe path do not work either:/usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
Error handle
connect(action, &QAction::triggered, [=](){ QProcess *process = new QProcess; //process->setWorkingDirectory(path); qDebug() << sExec; //process->start(sExec); //crash process->setProgram(sExec); connect(process, &QProcess::readyReadStandardError, [=](){ qDebug() << process->errorString(); //nothing }); bool b = process->startDetached(); qDebug() << b; //false //QProcess::startDetached(sExec, QStringList(), path); });
@sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
"/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
So, what do you want to start actually?! -
@sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
"/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
So, what do you want to start actually?! -
@sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
"/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
So, what do you want to start actually?! -
@sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
"/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
So, what do you want to start actually?!@jsulm said in QString replace %U:
@sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
"/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
So, what do you want to start actually?!deepin-draw is relative path.
google-chrome is absolute path.
I make openwith function, I can choose program to start. -
@jsulm said in QString replace %U:
@sonichy I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred
"/usr/bin/google-chrome-stable" - I don't get it - didn't you want to start deepin-draw before?
So, what do you want to start actually?!deepin-draw is relative path.
google-chrome is absolute path.
I make openwith function, I can choose program to start.@sonichy Third time: add error handling to see why QProcess fails to start the executable...
Also, sExec should NOT contain executable and parameter! Parameters to the executable are passed as another QStringList parameter https://doc.qt.io/qt-5/qprocess.html#setArguments -
@sonichy Third time: add error handling to see why QProcess fails to start the executable...
Also, sExec should NOT contain executable and parameter! Parameters to the executable are passed as another QStringList parameter https://doc.qt.io/qt-5/qprocess.html#setArguments -
@jsulm said in QString replace %U:
@sonichy Third time: add error handling to see why QProcess fails to start the executable...
Already add.
connect(process, &QProcess::readyReadStandardError, [=](){ qDebug() << process->errorString(); //nothing });
@sonichy said in QString replace %U:
Already add.
No.
You again did not read what I wrote: "I was talking about https://doc.qt.io/qt-5/qprocess.html#errorOccurred".
I'm out of this thread... -
-
If you mean that
qDebug() << sExec;
outputs/usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
then that is your problem. That line is not a program/executable, is it? The first word is the executable and the second word is an argument (and when passed as an argument it should not then have"
s around it). And if that is the case it would have saved a lot of time if you had shown this from the start. -
qDebug() << process->errorString(); //nothing
This is not what you are supposed to output if you receive some data on standard error, you are supposed to print the data you receive.
@JonB said in QString replace %U:
-
If you mean that
qDebug() << sExec;
outputs/usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
then that is your problem. That line is not a program/executable, is it? The first word is the executable and the second word is an argument (and when passed as an argument it should not then have"
s around it). And if that is the case it would have saved a lot of time if you had shown this from the start. -
qDebug() << process->errorString(); //nothing
This is not what you are supposed to output if you receive some data on standard error, you are supposed to print the data you receive.
/usr/bin/google-chrome-stable home/sonichy/Desktop/description.xml
falseAdd "*" is to include space in filename.
-
-
@jsulm said in QString replace %U:
@sonichy Third time: add error handling to see why QProcess fails to start the executable...
Already add.
connect(process, &QProcess::readyReadStandardError, [=](){ qDebug() << process->errorString(); //nothing });
@sonichy
In my previous post:-
I already told you what you need to do in
QProcess::readyReadStandardError
, you have not acted on it. -
I already told you that if
sExec
is/usr/bin/google-chrome-stable \"/home/sonichy/Desktop/description.xml\"
(or anything similar, with or without the quotes) that won't work, why it won't work, and what you need to do about it. But you did not answer (and now you have but not acted on what I said). And nor will plaindeepin-draw
, unless it is on yourPATH
I too am done.
-