Receiving warning C4189 "local variable is initialized but not specified", even if this variable is referenced

I have a piece of C ++ code using Qt where I try to run a batch file on the command line. I use the QProcess object to run cmd.exe and execute my batch file. The following 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 create it in Qt Creator, I get a warning:

warning: C4189: "process": local variable is initialized but not specified

The process variable is indicated on the last line of the function, and I cannot understand why this warning appears.

+6
source share
1 answer

This is because startDetached is a static member function. You can write process->startDetached(...) to specify a namespace in which the compiler will look for the member name instead of QProcess::startDetached(...) . But the two calls are identical; the call does not use the value of process .

+14
source

Source: https://habr.com/ru/post/969935/


All Articles