Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a warning C4189 "local variable is initialized but not referenced" even though the variable is being referenced

Tags:

c++

qt

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.

like image 837
adarsha joisa Avatar asked May 28 '14 04:05

adarsha joisa


1 Answers

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.

like image 198
rici Avatar answered Oct 23 '22 18:10

rici