I need the pointer to the specific object, that calls the method I'm in to compare the calling objects type to a specific type.
Here I cannot do it by using parent() and i cannot use sender() because the method is not called via signal/slot. Also it would take too much effort to pass the pointer as an argument because the "target" method is used by many classes and sometimes it's even used as a slot.
I need this for a big existing code so it's not a viable option to change the software structure. Sadly i have to deal with the software as it is.
void ClassA::callingFunction()
{
AnyObject *obj = new AnyObject();
obj->desiredMethod();
}
void ClassB::callingFunction()
{
AnyObject *obj = new AnyObject();
obj->desiredMethod();
}
void AnyObject::desiredMethod()
{
QObject *callingObject = ?
//Here i need a pointer to the instance of ClassA/ClassB which calls this method
bool bTypeMatch = typeid(*callingObject) == typeid(ClassA);
if(bTypeMatch) {...}
}