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

什么時(shí)候應(yīng)該使用 Q_OBJECT?

When should Q_OBJECT be used?(什么時(shí)候應(yīng)該使用 Q_OBJECT?)
本文介紹了什么時(shí)候應(yīng)該使用 Q_OBJECT?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

文檔指出:

Q_OBJECT 宏必須出現(xiàn)在類定義的私有部分聲明自己的信號(hào)和插槽或使用其他服務(wù)由 Qt 的元對(duì)象系統(tǒng)提供.

The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.

但是正是這是什么意思?在哪些 QObject 派生類上我可以安全地省略它?如果在 QObject 派生類上省略 Q_OBJECT,然后從該類繼承,會(huì)出現(xiàn)問(wèn)題嗎?基本上,我想了解更多有關(guān)何時(shí)可以從 Qt 類中省略它的信息.

But exactly what does that mean? On which QObject-derived classes can I safely omit it? Will problems arise if you omit Q_OBJECT on a QObject-derived class, and then inherit from that one? Basically I would like a little more information on when I can omit it from my Qt classes.

推薦答案

對(duì)于從 QObject 派生的任何非模板類,您應(yīng)該使用 Q_OBJECT.

You should use the Q_OBJECT macro for any non-templated classes that derive from QObject.

除了信號(hào)和槽之外,Q_OBJECT 宏提供了與給定類相關(guān)聯(lián)的元對(duì)象信息.

Besides signals and slots, the Q_OBJECT macro provides the meta object information that is associated with given class.

如文檔中所述:

我們強(qiáng)烈建議QObject 的所有子類都使用 Q_OBJECT 宏,無(wú)論它們是否實(shí)際使用信號(hào)、槽和屬性.

we strongly recommend that all subclasses of QObject use the Q_OBJECT macro regardless of whether or not they actually use signals, slots, and properties.

假設(shè)我們有以下類:

class Class : public QObject {
public:
  Class() {}
};

如果沒(méi)有 Q_OBJECT,以下元對(duì)象系統(tǒng)功能(以及其他)將不適用于 Class:

Without Q_OBJECT, the following metaobject system features (among others) will not work for Class:

  1. qobject_cast() - 由于缺少元數(shù)據(jù)

QObject::tr() - 由于缺少元數(shù)據(jù)

slots 和 invokables 首先在 Class 中聲明,當(dāng)按名稱調(diào)用或查找時(shí) - QMetaObject 方法都不適用于這些方法,Qt 也不會(huì)4 connect - 由于缺少元數(shù)據(jù)

slots and invokables first declared in Class, when invoked or looked up by name - none of QMetaObject methods will work for these methods, neither will the Qt 4 connect - due to missing metadata

信號(hào) - 因?yàn)?moc 不會(huì)生成它們的實(shí)現(xiàn),代碼也不會(huì)編譯.

signals - since moc won't generate their implementations and the code won't compile.

當(dāng)然,您可以省略它,但是如果您曾經(jīng)使用過(guò)這些功能,則需要記住將宏放入類的聲明中.這是一種相當(dāng)脆弱的做法,最好避免.節(jié)省的錢不值得.所以,不要等待 - 將 Q_OBJECT 宏添加到從 QObject 派生的每個(gè)類中,作為編碼策略的問(wèn)題.

You can omit it, of course, but if you ever use these features, you'll need to remember to put the macro into the class's declaration. This is a rather brittle practice and best avoided. The savings are not worth it. So, don't wait - add the Q_OBJECT macro to every class that derives from QObject as a matter of coding policy.

Q_OBJECT 宏應(yīng)該永遠(yuǎn)用在不是從 QObject 派生的類上.要將可調(diào)用項(xiàng)和屬性添加到此類類,請(qǐng)改用 Q_GADGET 宏.

The Q_OBJECT macro should never be used on classes that don't derive from QObject. To add invokables and properties to such classes, use the Q_GADGET macro instead.

這篇關(guān)于什么時(shí)候應(yīng)該使用 Q_OBJECT?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫(xiě) for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 久久久久久久久久久久91 | 欧美二区在线 | 91精品国产综合久久婷婷香蕉 | 国产欧美三区 | 91久久精品 | 中文字幕日韩欧美一区二区三区 | 国产精品福利在线 | 欧美伊人影院 | 欧美一级视频在线观看 | 自拍偷拍第一页 | 日韩一区二区福利视频 | 亚洲精品黄色 | 日本不卡一区二区三区 | 欧美性tv | 成人在线电影网站 | 日本精品一区二区三区在线观看视频 | 欧美色综合 | 欧美日韩专区 | 亚洲一区 中文字幕 | 最新av在线播放 | 日本成人三级电影 | 中文字幕日韩欧美一区二区三区 | av中文字幕在线播放 | 九九国产| 国产精品一区2区 | 久久免费高清视频 | 91精品久久久久久久久 | 国产精品入口 | 亚洲一二三区av | 精品成人av| 日本电影韩国电影免费观看 | 精品乱码久久久久 | 特黄毛片视频 | 亚洲精品综合 | 日本福利一区 | 新av在线| 亚洲综合大片69999 | 久草视频在线看 | 天天拍天天草 | 一区二区三区四区五区在线视频 | 中文字幕 欧美 日韩 |