久久久久久久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 ()?環形?)
主站蜘蛛池模板: 三级黄色网址 | 天天视频国产 | 欧美视频一区二区三区 | 人人插人人爱 | 日韩国产在线播放 | 久久九九热 | 欧美激情视频网站 | 久久久久久伊人 | 在线观看a视频 | 男女瑟瑟视频 | 国产成人免费观看 | 人人射人人 | 欧美精品二区三区四区免费看视频 | 日韩精品久久久久久久酒店 | 色哟哟精品观看 | 久久一级视频 | 天天草天天射 | 97在线观看免费视频 | 91看片在线观看 | 福利视频一区二区 | 在线免费国产 | av一区二区在线观看 | 老司机久久 | 日本精品中文字幕 | 96精品| 色www| 国产精品乱码一区二区视频 | 日韩欧美色图 | 青青久久久 | 天天摸夜夜操 | 亚洲激情欧美 | 特黄一级视频 | www.日本黄色 | 美国一级大黄一片免费中文 | 懂色av一区二区三区 | 欧美一级免费 | 人人干人人看 | 日韩一区二区免费视频 | av网站免费在线观看 | 久久综合99 | 亚洲视频中文字幕 |