Short question: Is there any way in Qt to hook or sniff an existing SLOT? Or maybe connect a SLOT to another SLOT? Without changing the implementation of the existing SLOT? Like an observer to get informed if the slot is called from somewhere in the system.
TL;DR
I want to refactor an old Qt application, which uses a huge and buggy singleton to host and manage different widgets and handle communication between them. In the first step I don’t want to change all the hosted widgets, because there are many of them. And I don’t want to update all installations of my old singleton. So changing the singleton is not an option for me. Let’s bring a little bit pseudo code in here, first the singleton.
class UgglyOldSingleton
{
private:
UgglyOldSingleton();
~UgglyOldSingleton();
QList allRegistedWidgets;
public:
static UgglyOldSingleton *instance();
void registerMe(oldInterface obj);
public slots:
void sendMessageToTarget(QString targetName, QString message);
void action2();
…
}
How it works?
Every used widget is implemention the oldInteface and on startup register on the singleton. Via singleton::instance->sendMessageToTarget() they can exchange information or commands to widgets there don’t know each other directly. Long time ago I think this was a cool solution.
But having too much widgets on the singleton creates many problems, I don’t want to discuss it here. And please don’t discuss or complain about the old architecture, it doesn’t help me out! I already spend hours of research to find an solution, hope someone of you guys can assist me. If you need any further information, please feel free to ask about it.
what you want is the GammaRay application that let's you introspect Qt applications in runtime. With no changes in your code, you load Gammaray and launch your application, it will read all QObjects, signals and slots and give you all the information you need (plus a bunch more).