[solved] Which object type is QObject::sender()?
Hi mates!
When I receive a signal, I'd like to know in my SLOT if the sender is a QDockWidget, how can I test which kind of object is QObject::sender()?
There is a method called isA but I guess is obsolete because is not available on qt4.5
Any idea?
Thanks in advance.
EDIT:
BTW, Why doesn't work this:
QDockWidget* dock=(QDockWidget*) QObject::sender();
But this works perfectly:
QObject* sender = const_cast<QObject*>(QObject::sender());
QDockWidget* dock = static_cast<QDockWidget*>(sender);
Re: Which object type is QObject::sender()?
simply cast sender() to QDockWidget and see if the pointer is valid.
Re: Which object type is QObject::sender()?
Re: Which object type is QObject::sender()?
Quote:
Originally Posted by
ricardo
QObject* sender = const_cast<QObject*>(QObject::sender());
QDockWidget* dock = static_cast<QDockWidget*>(sender);
you also can use the Qt way
Re: Which object type is QObject::sender()?
Quote:
Originally Posted by
Lykurg
simply cast sender() to QDockWidget and see if the pointer is valid.
Do you mean !=NULL?
Re: Which object type is QObject::sender()?
Quote:
Originally Posted by
ricardo
Do you mean !=NULL?
From the docs:
Quote:
T qobject_cast ( QObject * object )
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns 0.
So
Code:
if(dock)
{
// sender is a QDockWidget
}
... if you only dealing with a small number of dock widgets in you application and the slot has a pointer to them you can also of course use:
Code:
if (myglobalpointer
== QObject::sender()) //...
Re: Which object type is QObject::sender()?
Quote:
Originally Posted by
Lykurg
From the docs:
So
Code:
if(dock)
{
// sender is a QDockWidget
}
... if you only dealing with a small number of dock widgets in you application and the slot has a pointer to them you can also of course use:
Code:
if (myglobalpointer
== QObject::sender()) //...
Thanks a lot. Solved.