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

使用發射與調用信號,就好像它是 Qt 中的常規函

Using emit vs calling a signal as if it#39;s a regular function in Qt(使用發射與調用信號,就好像它是 Qt 中的常規函數??一樣)
本文介紹了使用發射與調用信號,就好像它是 Qt 中的常規函數??一樣的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

假設我有這個信號:

signals:
    void progressNotification(int progress);

我最近才知道 Qt 中的 emit 關鍵字.到現在為止,我曾經通過像普通函數一樣調用它們來執行信號.所以,而不是:

I only recently learned about the emit keyword in Qt. Until now, I used to execute signals by just calling them like a regular function. So instead of:

emit progressNotification(1000 * seconds);

我會寫:

progressNotification(1000 * seconds);

像這樣調用它們似乎可行,并且所有連接的插槽都會執行,所以使用emit 關鍵字會導致不同的行為,還是只是語法糖?

Calling them like that seemed to work, and all the connected slots would execute, so does using the emit keyword cause a different behaviour, or is it just syntactic sugar?

推薦答案

emit 只是語法糖.如果您查看發出信號的函數的預處理輸出,您會看到 emit 剛剛消失.

emit is just syntactic sugar. If you look at the pre-processed output of function that emits a signal, you'll see emit is just gone.

魔術"發生在信號發射函數的生成代碼中,您可以通過檢查由 moc 生成的 C++ 代碼來查看.

The "magic" happens in the generated code for the signal emitting function, which you can look at by inspecting the C++ code generated by moc.

例如一個沒有參數的 foo 信號生成這個成員函數:

For example a foo signal with no parameters generates this member function:

void W::foo()
{
    QMetaObject::activate(this, &staticMetaObject, 0, 0);
}

并且代碼emit foo();被預處理為簡單的foo();

And the code emit foo(); is pre-processed to simply foo();

emitQt/qobjectdefs.h 中定義(無論如何都是開源的),像這樣:

emit is defined in Qt/qobjectdefs.h (in the open-source flavor of the source anyway), like this:

#ifndef QT_NO_EMIT
# define emit
#endif

(定義保護是允許您通過 no_keywords QMake 配置選項將 Qt 與具有沖突名稱的其他框架一起使用.)

(The define guard is to allow you to use Qt with other frameworks that have colliding names via the no_keywords QMake config option.)

這篇關于使用發射與調用信號,就好像它是 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丨 | 亚洲播放 | 韩日视频在线观看 | 欧美激情a∨在线视频播放 成人免费共享视频 | 日本在线黄色 | 国产日韩一区二区三区 | 中文字幕亚洲视频 | 国产精品久久久久久久午夜 | 久久久久精 | 在线观看成人免费视频 | 国产成人精品福利 | 国产精品久久久久久久久免费 | 男女一区二区三区 | 亚洲一区中文 | aaa一区| 亚洲成人激情在线观看 | 在线观看视频一区 | 国产精品中文字幕在线 | 精品国产一区二区三区久久狼黑人 | 97视频在线免费 | 亚洲欧洲成人 | 午夜日韩 | 欧美日韩一区二区电影 | 国产精品久久国产精品 | 久久精品免费 | 国产亚洲精品久久午夜玫瑰园 | av网站在线看 | 日韩国产在线 | 日干夜干 | 欧美久久久久久久 |