Use singleton mode in Qt to be careful

Source: Internet
Author: User
In Qt, be careful when using singleton mode. Because static objects are used in singleton mode, static objects are not released until the end of the program, but once the static object is included in the QT parent-child system, it can lead to ambiguous behavior. And, even if we are careful not to pass the parent pointer over the constructor (that is, not to make a parent object for the static object), it is possible to redefine the parent object according to some mechanism of QT, which is the most deadly and most easily overlooked. So, using singleton mode in Qt, which is exactly "static object", be careful, especially those nested window classes that inherit from Qwidget, and even if we don't set the parent object for them, they will redefine the parent itself. By then, we may not be able to find the cause of the program crash.

Use singleton mode in Qt to be careful

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.