[Interest] Most simple emit from singleton?

Jason H jhihn at gmx.com
Wed Nov 13 18:11:35 CET 2019


Maybe. Couldn't I just call:
MySingleton::Instance()->MySignal();

and skip emit altogether? I've read that Q_EMIT and emit are just syntactic sugar, and there is confusion in this stackexchange:
https://stackoverflow.com/questions/10160476/using-emit-vs-calling-a-signal-as-if-its-a-regular-function-in-qt

it seems that the simplest way is just:
MySingleton::Instance()->MySignal(); 

but to make it clear it is emitting, the sugar comes into play. Not sure if it has any affect on queued vs direct-call connections though. (I'm guessing no)





> Sent: Wednesday, November 13, 2019 at 10:33 AM
> From: "Jérôme Godbout" <godboutj at amotus.ca>
> To: "Jason H" <jhihn at gmx.com>, "interestqt-project.org" <interest at qt-project.org>
> Subject: RE: [Interest] Most simple emit from singleton?
>
> Why not declare a signals into your singleton header and call it directly?
> 
> MySingleton.h
> 
> class MySingleton
> {
> signals:
>    void MySignals();
> };
> 
> myOtherCode.cpp
> 
> Q_EMIT  MySingleton::Instance()->MySignals();
> 
> 
> -----Original Message-----
> From: Interest <interest-bounces at qt-project.org> On Behalf Of Jason H
> Sent: November 13, 2019 11:28 AM
> To: interestqt-project.org <interest at qt-project.org>
> Subject: [Interest] Most simple emit from singleton?
> 
> I've stumbled across a paradigm that I am starting to use frequently where I have a singleton, and I want it to emit something when I tell it to.
> 
> So I've been providing a function and doing: MySingleton::instance()->emitMySignal();
> 
> Where:
> void MySingleton::emitMySignal() {
>     emit mySignal();
> }
> 
> But this seems "silly". Is there a better way to do this? Ideally I'd like to skip creating the function and do something like:
> 
> MySingleton::instance()->emit MySignal(); or emit MySingleton::instance()->MySignal();
> 
> 
> There may still be a better way?
> 
> Thoughts?
> 
> Thanks!
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>


More information about the Interest mailing list