久久久久久久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 ()?環形?)
主站蜘蛛池模板: 日韩欧美国产精品 | 国产免费小视频 | 午夜精品影院 | 99热国产在线 | www.av在线播放 | 国产在线不卡 | 久久久久综合 | 成人高清免费 | 久久手机免费视频 | 欧美日韩国产在线播放 | 午夜性视频 | 天堂av中文在线 | 免费av一区二区三区 | 欧美极品一区 | 日韩中文字幕在线 | www.九色 | 欧美日本在线 | 999毛片| 成人黄色免费视频 | 黄色片网站视频 | 97在线视频观看 | 午夜在线 | 日韩理论在线 | 成人在线免费视频 | 800av在线播放 | www.三级| 成人精品免费 | 91一级片 | 一级黄色大片 | 日韩免费在线观看视频 | a级片免费观看 | av免费观看网址 | 国产乱码一区二区三区 | 久久天堂网 | 亚久久| 一区久久 | 日韩av中文字幕在线播放 | 91成人精品一区在线播放 | 神马午夜视频 | 九九九视频 | 欧美日韩国产精品 |