Welcome: Hunan Intelligent Applications Tecgnology CO.,ltd.-HNIAT.com
Language: Chinese ∷  English

Basic knowledge

Solution: error: Class declaration lacks Q_OBJECT macro. error

1. The introduction of the problem
Recently, I was practicing the knowledge of signals and slots. During the learning process, I reported the error shown in the following screenshot:

According to the error report: The Q_OBJECT macro was not added.

2. Problem solving
Only by adding Q_OBJECT, you can use the signal and slot mechanism in QT. In order to use signals and slots, Q_OBJECT must be inherited.
Any QObject class (whether it is a direct subclass or an indirect subclass) should write Q_OBJECT on the first line of code. This macro should be added regardless of whether signals and slots are used. The expansion of this macro will provide our class with the signal-slot mechanism, the internationalization mechanism, and the non-C++ RTTI-based reflection capabilities that Qt provides. Therefore, if you think your class does not need to use signals and slots, it is wrong not to add this macro. Many other operations depend on this macro.

———————————————
Copyright statement: This article is an original article by CSDN blogger "shuxin7782" and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/shuxin7782/article/details/113356706

CONTACT US

Contact: Manager Xu

Phone: 13907330718

Tel: 0731-22222718

Email: hniatcom@163.com

Add: Room 603, 6th Floor, Shifting Room, No. 2, Orbit Zhigu, No. 79 Liancheng Road, Shifeng District, Zhuzhou City, Hunan Province

Scan the qr codeClose
the qr code