September 30, 2011

gosk gosk
Lab Rat
10 posts

run system() command through qt application

 

Hi,

I cross compiled my qt application and it runs well on my arm development platform. What I want is to run a system() command when a button is pressed.I did something like follow in button’s clicked() function.

  1. Qstring command="cp -r /my_location1 /my_location2";
  2. const char* command2;
  3.  
  4. command2 =command.toLocal8Bit().data();
  5. system(command2);

this worked perfecly on my pc. but on target it didnt work.
I ran my application with ./my_app -qws command. can anyone help me

thank you.

7 replies

September 30, 2011

Lukas Geyer Lukas Geyer
Gene Splicer
2074 posts

You might use QProcess [doc.qt.nokia.com] instead.

September 30, 2011

peppe peppe
Ant Farmer
1025 posts

Using system(3) is usually a bad idea. But the error there is

  1. command2 =command.toLocal8Bit().data();

command2 is a dangling pointer after that statement.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

September 30, 2011

gosk gosk
Lab Rat
10 posts

Hi ,

thanks a lot. I’ll try with qprocess and let you know the result.

October 1, 2011

gosk gosk
Lab Rat
10 posts

Hi,

It didn’t work. I don’t know it has something to do with using -qws option when executing the program in the target. Because the same program works perfectly in my host computer.

thank you.

October 1, 2011

koahnig koahnig
Mad Scientist
2099 posts

Probably you shold post at least a section of code showing the implementation of QProcess. Furthermore, it might help to provide the error messages, if any.

October 1, 2011

uranusjr uranusjr
Lab Rat
77 posts

Based on my personal experiences, both system() and QProcess should work on embedded devices running QWS, so the -qws option doesn’t seem to be the problem (at least not the real problem). Perhaps some information about you devices may help, too.

On the other hand, if you are only interested in copying files, you can consider using QFile’s copy function [doc.qt.nokia.com] instead. It should be pretty easy to use.

October 1, 2011

gosk gosk
Lab Rat
10 posts

HI,

I could resolve the problem. It was a silly mistake. I had used “pushButton_clicked()” function to execute my command whereas it should have been “pushButton_pressed()” function. Now the system works perfectly. thank you everyone. I learnt a lot from you. :)

 
  ‹‹ Remote Debugging using QT on ARM      [Solved] problem compiling gdigicam app on qt creator ››

You must log in to post a reply. Not a member yet? Register here!