Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using system command in Qt

Tags:

qt

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?

like image 956
harnek singh Avatar asked May 29 '12 12:05

harnek singh


2 Answers

Use the qPrintable() macro

system(qPrintable(command));

like image 79
Vinicius Kamakura Avatar answered Oct 04 '22 20:10

Vinicius Kamakura


You need get the raw character array from the QString. Here is one way:

system(command.toStdString().c_str());
like image 44
Jason B Avatar answered Oct 04 '22 22:10

Jason B