Results 1 to 3 of 3

Thread: Ho to use signals and slots to execute a command?

  1. #1
    Join Date
    Jul 2008
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Ho to use signals and slots to execute a command?

    Here is my guess:

    I create an object and I define a method. I link the action (signal) to the method (slot). The method, in this case, should contain a command launched on a system's shell.

    Is that - at least in part - right?!
    Last edited by claudio-cit; 3rd July 2008 at 21:34.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Ho to use signals and slots to execute a command?

    basically yes, the slot is not the shell command, but rather executes it.
    Qt Code:
    1. class ClassA : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ClassA();
    7.  
    8. signals:
    9. void someSignale();
    10. };
    11.  
    12. class ClassB : public QObject
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. ClassB();
    18. public slots:
    19. someSlot()
    20. {
    21. system("some shell command");
    22. }
    23. };
    24.  
    25.  
    26. // somewhere else
    27. ClassA a;
    28. ClassB b;
    29.  
    30. b.connect(&a, SIGNAL(someSignal()), SLOT(someSlot()));
    31.  
    32.  
    33. somewhere in ClassA:
    34. emit someSignal();
    To copy to clipboard, switch view to plain text mode 

    When ClassA emits this signal, all the slots connected to it will be executed (in an undefined order).
    In a slot you may execute any code you like, e.g. call some shell command.

    Read up the tutorials etc in the excellent Qt docs!

    HTH.

  3. #3
    Join Date
    Jul 2008
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Ho to use signals and slots to execute a command?

    Very helpfull! Thank you very much.

Similar Threads

  1. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  2. Signals and Slots Across Threads
    By themusicalguy in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 11:16
  3. help with signals and slots
    By superutsav in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2006, 12:49
  4. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11:35

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.