Role of template functions in the signal Slot Mechanism

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.