As previously written, ShowButton is a custom control inherited from QGraphicsWidget.
ShowButton * button = qobject_cast <ShowButton *> (sender ());
This sentence means that the QObject pointer of the sender () signal can be forced to obtain the desired type,
See the template function here.
Template <class T>
Inline T qobject_cast (QObject * object)
{// This is the definition of the template function. if the object is of the T type or its own thunder, the object can be returned as a T-type object, provided that the Q_OBJECT macro is included.
}
We observe that sender () is a subclass of QGraphicsWidget, while QGraphicsWidget inherits from QGraphicsObject and QGraphicsObject inherits from QObject. Therefore, this sender () can indeed be passed to the object as a real parameter, then the function qobject_cast converts it to the desired ShowButton * type.
This article from the "selling cute programmers" blog, please be sure to keep this source http://7677869.blog.51cto.com/7667869/1265607