PDA

View Full Version : How to execute linux command upon button press?



namus
17th May 2010, 16:09
I am a newbie to QT

i wrote a program in which window has a delete button ,upon delete press i need to execute the command "rm -rf /home/Desktop/DEL/*"
How should i use connect( ) ?

sender is b1
signal is : clicked ()

receiver is p1 object.
what function should i need for slot , inorder to execute the above command ?


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
window->setWindowTitle("Dialog ");

//QProcess *p1 = new QProcess(window);
//p1->start ( "rm -rf /home/Desktop/DEL/* ", QIODevice::ReadWrite);

QPushButton *b1 = new QPushButton("delete", window);
// QObject::connect(b1,SIGNAL(clicked()),p1, );

window->show();
return app.exec();
}


further ,

in connect () , is receiver object is must ? cant i give receiver object as NULL & for slot ,can i give any function like my_function() ?

Lykurg
17th May 2010, 16:15
Make a slot in which you create a QProcess which executes your command. Then use the buttons click signal and connect it to your slot. See the documentation about signal and slots.