問題描述
我剛開始使用 Qt 并注意到所有示例類定義都將宏 Q_OBJECT
作為第一行.這個預處理器宏的目的是什么?
I just started using Qt and noticed that all the example class definitions have the macro Q_OBJECT
as the first line. What is the purpose of this preprocessor macro?
推薦答案
來自 Qt 文檔:
元對象編譯器,moc,是處理 Qt 的 C++ 的程序擴展.
The Meta-Object Compiler, moc, is the program that handles Qt's C++ extensions.
moc 工具讀取 C++ 頭文件.如果找到一個或多個類包含 Q_OBJECT 的聲明宏,它生成一個 C++ 源文件包含元對象代碼那些課.除其他事項外,需要元對象代碼信號槽機制運行時類型信息,以及動態屬性系統.
The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes. Among other things, meta-object code is required for the signals and slots mechanism, the run-time type information, and the dynamic property system.
這篇關于Q_OBJECT 宏有什么作用?為什么所有 Qt 對象都需要這個宏?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!