View Full Version : Ho to use signals and slots to execute a command?
claudio-cit
3rd July 2008, 22:21
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?!
caduel
3rd July 2008, 22:39
basically yes, the slot is not the shell command, but rather executes it.
class ClassA : public QObject
{
Q_OBJECT
public:
ClassA();
signals:
void someSignale();
};
class ClassB : public QObject
{
Q_OBJECT
public:
ClassB();
public slots:
someSlot()
{
system("some shell command");
}
};
// somewhere else
ClassA a;
ClassB b;
b.connect(&a, SIGNAL(someSignal()), SLOT(someSlot()));
somewhere in ClassA:
emit someSignal();
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.
claudio-cit
3rd July 2008, 23:01
Very helpfull! Thank you very much.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.