[Interest] Most simple emit from singleton?

Jérôme Godbout godboutj at amotus.ca
Wed Nov 13 17:33:06 CET 2019

Why not declare a signals into your singleton header and call it directly?


class MySingleton
   void MySignals();


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();

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?



Interest mailing list
Interest at qt-project.org

More information about the Interest mailing list