We can emit signals in the class defining the signals easily by emit signal_a()
like
class A
{
signals:
signal_a();
public:
void fun()
{
do_something();
emit signal_a();
do_something();
}
};
However, How to emit signals in another class in Qt? For example
class B
{
public:
void fun()
{
do_something();
(*a) emit signal_a(); // ???
do_something();
}
A* a;
};
You can't emit signals directly, because signals are protected methods (in Qt4). There are several ways to do what you want:
You should remember, that classes with signals must interhit QObject and contain Q_OBJECT macro.
In Qt5, you can just do
emit a->signal_a();
emit
is an empty macro and signals are set public (the signals
"keyword is a macro that becomes public
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With