I wanted to know if its possible to emit some specific signal through coding .. For example, I want to emit another button's clicked event without the user actually clicking that button .. can do I do this ?
Signals are internally implemented as C++ private member functions, so I'd advise against doing so.
You could call that other button's click function. It will emit the clicked signal.
Qt, throught the moc, implement the emit keyword, that allow you to emit signals throught coding.
If the Class that you are using doesn't provide a method for emit some signal, you can Subclass it, and implement a function that does it yourself. But I must say that I had never done this for "normal" signals. Only did it when I defined my own signals in some class extension.
Instead of emitting the signal by yourself and connecting it to the slot, why cant you call the slot directly? Slots are just like other C++ functions, in the sense that you can call it directly. I don't see any reason where you have emit a predefined signal (like clicked()
). Just call your slot directly.
to emit a signal you just write
emit signalName(param list);
#include <QObject>
class myClass : public QObject
{
Q_OBJECT
public:
myClass (QObject *parent = 0) : QObject(parent) { }
void foo();
signals:
void mySignal(int param);
};
void myClass::foo() { emit mySignal(5); }
read more at http://doc.trolltech.com/4.6/signalsandslots.html
you can also connect a signal to another signal so you can connect mysignal to the buttons clicked signal and when your signal is emited the clicked signal will also be emited see http://doc.qt.nokia.com/4.6/qobject.html#connect