What does it mean when an entire function is a slot?
-
-
@JonB No I am being a fool it was a slot. I was confusing
updateStatus()
withstatusUpdate()
which is another signal. Sorry bare with me I am new to signals/slots and Qt in general. In general, I would like to be able to send this slot a signal from outside of this class, will it need to be a public slot for that to happen? If I can call it directly from the QML then great but if I have to call it from within the c++ code using this Q_INVOKABLE fcarney referred to than that's fine too, so long as I can call something like:onUpdateStatus:
from the QML, eventually, one way or another.
-
@JonB I am just a bit confused. It would seem that I have a signal, which is connect to a signal which is connected to a normal method?? The method these signals seem to be connect to is not a slot. For instance:
The header:
signals: void gnssStatusChanged(QStringList);
It's corresponding c++ file:
QObject::connect(m_a, &Application::statusChanged, this, &GnssPresenter::gnssStatusChanged); Q_ASSERT(rc); }
statusChanged
leads to another header:signals: void statusChanged (QStringList const&);
also inside that header this
statusChanged
seems to be hooked up to a variable called status:class ApplicationInterface : public QObject { Q_OBJECT Q_PROPERTY(QStringList const& status READ status NOTIFY statusChanged)
and when I right-click
status
and click find references it shows two of them in another c++ file and corresponding header:
from the header:QStringList const& status() const override;
from the c++ file:
QStringList const& MockGnssApplication::status() const { return m_status; }
the header and c++ file above is where the
updateStatus()
method I was referring to earlier is located. So like I said, it would seem I have a signal hooked to a signal which is hooked to a normal method which is located in the file where theupdateStatus()
method (slot) is located.What is confusing me:
- Must a signal hook up to a slot or can it hook up to a normal method?
- What is happening in this line:
Q_PROPERTY(QStringList const& status READ status NOTIFY statusChanged)
this seems to be a signal/slot syntax without actually having a slot.
-
Hi,
It is allowed and has even a name: signal chaining.
This allows to propagate a signal upper while not making the internals public.
-
@SGaist Thanks~ Still confused about what
emit
does. I found lots ofsignals
declared in headers with no correspondingemit
call in the c++ file. Perhaps thisemit
isn't necessary?In any case, I think what I need to do is generate a new signal and connect it too the
updateStatus()
slot. Can I just do that directly from the QML, in this case? -
Technically speaking,
emit
is replaced by nothing (take a look at the macro). However, it does make the code more understandable with regard to what should happen at that point. It make also clear that you are calling a signal. -
@SGaist said in What does it mean when an entire function is a slot?:
Technically speaking,
emit
is replaced by nothing (take a look at the macro). However, it does make the code more understandable with regard to what should happen at that point. It make also clear that you are calling a signal.+1
In other words...
void MyClass::func() { emit mySignal(); // [1] mySignal(); // [2] }
... [1] and [2] are exactly the same from a compiler's point of view. However, [2] is clearer to a human reader.