I have a piece of C++ code using Qt where I try to run a batch file in the command prompt. I use a QProcess
object to start cmd.exe
and execute my batch file. Below is the code I'm using:
void Utility::executeBatchFile(QString batchFile)
{
QProcess *process = new QProcess(this);
QString cmdName = "cmd.exe";
QStringList arguments;
arguments<<"/k" << batchFile;
process->startDetached(cmdName, arguments);
}
When I build it in Qt Creator, I get a warning:
warning: C4189: 'process' : local variable is initialized but not referenced
The variable process
is referenced in the last line of the function, and I'm unable to figure out why exactly this warning appears.
It's because startDetached
is a static member function. You're allowed to write process->startDetached(...)
in order to indicate the namespace in which the compiler will look for the member name, instead of QProcess::startDetached(...)
. But the two invocations are identical; the call does not use the value of process
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With