cwinapilpstr

How to resolve “ invalid conversion from 'const char*' to 'LPSTR {aka char*}' [-fpermissive] "


I use Qt Creator and this code :

CreateProcess(NULL,string("curl -F \"api_key=XXX\" -F \"filetype=mp3\" -F \"track=@"+execpath+"\\sound.mp3\" \"http://developer.echonest.com/api/v4/track/upload\"").c_str(), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &startupinfo, &procinfo); // Send sound.mp3 to be analyzed by Echonest

generate this issue:

invalid conversion from 'const char*' to 'LPSTR {aka char*}

How to solve it?

Note that I have defined :

DEFINES -= UNICODE

in my .pro file


Solution

  • You need to read documentation on CreateProcess() carefully. Second argument is marked as inout, meaning the function would (in this case, could) modify the value pointed to.

    If you're going to make a cast the way you mention in comments, it is better to not only add a comment but also probably use ANSI function explicitly (thus calling CreateProcessA()) just in case.

    Also, Qt has its own way of creating processes. You could refer to QProcess documentation.