久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么包含“.moc"很重要?Qt 源代碼文件末尾的

Why is important to include quot;.mocquot; file at end of a Qt Source code file?(為什么包含“.moc很重要?Qt 源代碼文件末尾的文件?)
本文介紹了為什么包含“.moc"很重要?Qt 源代碼文件末尾的文件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

為什么在 Qt cpp 源代碼中為 .moc 文件添加一個包含很重要?

Why is it important to add an include for .moc file in a Qt cpp source code?

這是幾個Qt示例中常用的步驟,包括這個:http://doc.qt.io/qt-5/qttestlib-tutorial1-example.html; 其中行 #include "testqstring.moc" 應該包含在文件的末尾.

This is a common step used in several Qt samples, including this one: http://doc.qt.io/qt-5/qttestlib-tutorial1-example.html; where the line #include "testqstring.moc" should be included in the end of the file.

我不明白為什么這是必要的.

I don't understand exactly why this is necessary.

推薦答案

如果您在 中使用 Q_OBJECT 宏定義 QObject 子類,則這是必要的.cpp 文件.這樣做時:

It's necessary if you define QObject subclasses with the Q_OBJECT macro in a .cpp file. When you do so:

  1. qmake 必須在您的 Makefile 中生成規則以在該 .cpp 上調用 moc> 文件.

  1. qmake must generate rules inside your Makefile to invoke moc on that .cpp file.

那個特殊的(hackish?)包含會觸發 qmake 這樣做,并告訴它哪個將是 moc 的輸出文件 (teststring.moc) 在您的 .cpp 上調用時.

That special (hackish?) inclusion triggers qmake to do so, and tells it which would be moc's output file (teststring.moc) when invoked on your .cpp.

為了編譯moc的輸出(仍然是一堆C++代碼),編譯器必須看到你的類定義.否則,它會抱怨沒有諸如 YourClass::staticMetaObject 之類的東西,因為它不知道 YourClass 存在.

In order to compile moc's output (which is still a bunch of C++ code) the compiler must see your class definition. Otherwise, it will complain that there's no such thing as YourClass::staticMetaObject and similar, because it has no idea that YourClass exists.

通常在頭文件中定義具有 Q_OBJECT 的類.moc 然后在其生成的輸出中添加一個 #include "header.h",這意味著 moc 的輸出可以被愉快地編譯.

Typically one defines classes featuring Q_OBJECT in a header file. moc then adds a #include "header.h" into its generated output, and this means moc's output can be happily compiled.

但是如果您的類定義在 .cpp 中呢?您不能在 moc 的輸出中 #include 一個 .cpp 文件,因為這會給您帶來大量的重新定義錯誤.

But what if your class definition is inside a .cpp? You can't #include a .cpp file in moc's output, as that would give you tons of redefinition errors.

相反,您將#include moc 的輸出放在.cpp 中,以便將其編譯在一起,每個人都很高興.(這意味著 qmake 只會發出一個規則,說運行 moc,而不是另一個規則告訴編譯器編譯 moc 的輸出.)

Instead, you #include moc's output in your .cpp, so that it gets compiled together and everyone is happy. (This means qmake will only emit one rule saying to run moc, but not another rule telling the compiler to compile moc's output.)

從 2. 您還可以假設在 .h 中使用 Q_OBJECT 定義類不需要任何特殊包含.

From 2. you can also also desume that defining classes with Q_OBJECT in a .h does not require any special inclusion.

這篇關于為什么包含“.moc"很重要?Qt 源代碼文件末尾的文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 久久草在线视频 | 久久久免费少妇高潮毛片 | 亚洲国产精品福利 | 欧美成人激情 | 国产精品区二区三区日本 | www.日韩av.com | 国产精品久久久久久238 | 久草网站| 欧美色成人 | 激情婷婷 | 在线亚洲欧美 | 成人久久久| 欧美久久精品一级黑人c片 91免费在线视频 | 欧美二区在线 | 亚洲成人一区二区三区 | 午夜激情一区 | 久久国产精品99久久久久 | 久久婷婷国产麻豆91 | 亚洲精彩视频 | 国产视频一区二区 | 黄色大片在线免费观看 | 免费观看av| 一区二区三区亚洲精品国 | 免费观看成人性生生活片 | 一区二区三区视频在线 | 精品国产精品一区二区夜夜嗨 | 成人国产免费视频 | 中国一级特黄真人毛片免费观看 | 日韩成人在线视频 | 精品国产一区二区三区久久 | 日韩播放 | 爱草在线 | 亚洲精品在线视频 | 黄色av观看| 亚洲精品一区二区三区在线 | 天天搞天天操 | 国产在线一区二区三区 | 久久9精品 | 国产一区二| 怡红院成人在线视频 | 国产精品99精品久久免费 |