Results 1 to 2 of 2

Thread: How to execute linux command upon button press?

  1. #1
    Join Date
    May 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default How to execute linux command upon button press?

    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() ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to execute linux command upon button press?

    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.

Similar Threads

  1. How do I execute an .schema command using Qt's SQLITE driver?
    By danielperaza in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2010, 21:21
  2. Replies: 2
    Last Post: 10th November 2009, 07:17
  3. make[2]:arm-linux-g++:Command not found.(Greenphone SDK)
    By rishiraj in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 17th April 2009, 14:57
  4. Ho to use signals and slots to execute a command?
    By claudio-cit in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2008, 23:01
  5. Linux/Bash: Run a command as another user
    By sunil.thaha in forum General Discussion
    Replies: 1
    Last Post: 5th December 2006, 10:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.