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

StackOverflow https://stackoverflow.com/questions/21957973

  •  15-10-2022
  •  | 
  •  

문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top