How can I use the system
command where the command is written in a QString?
Like:
QString command="chmod -R 777 /opt/QT/examples/code/TestGUI/Data";
system(command);
While compiling, I get this error:
cannot convert ‘QString’ to ‘const char*’
for argument ‘1’ to ‘int system(const char*)’
Can anyone suggest something?
Use the qPrintable()
macro
system(qPrintable(command));
You need get the raw character array from the QString. Here is one way:
system(command.toStdString().c_str());
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