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

每次發(fā)出信號時都會多次調(diào)用插槽

Slot is being called multiple times every time a signal is emitted(每次發(fā)出信號時都會多次調(diào)用插槽)
本文介紹了每次發(fā)出信號時都會多次調(diào)用插槽的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在一個塊中使用一個信號和插槽連接.我的代碼如下

I am using one signal and slot connection in a block. My code as follows

在 a.cpp 中

{
 QObject::connect(m_ptheFlange2Details,SIGNAL(GetFlang1DimAfterAnalysis()),
                 this,SLOT(GetFlang1DimAftrAnalysis()));

 m_ptheFlange2Details->get();// one function inside which i am emiting
                             // GetFlang1DimAfterAnalysis() signal ;

 QObject::disconnect(m_ptheFlange2Details,SIGNAL(GetFlang1DimAfterAnalysis()),
                     this,SLOT(GetFlang1DimAftrAnalysis()));

}

當這個emit 語句執(zhí)行時,在get() 函數(shù)中,槽被調(diào)用了很多次.根據(jù)我的說法,它應該只調(diào)用一次.

Inside the get() function when this emit statement executes, the slot is called lots of times. Where as according to me it should call only once.

推薦答案

正如一些評論中所述,這通常是由于多次調(diào)用 connect 造成的.每次建立連接時都會調(diào)用一次插槽.例如,下面的代碼將導致 slot()signal() 被發(fā)射一次時被調(diào)用 3 次.

As stated in some of the comments, this is usually caused by calling the connect more the once. The slot will be called once for every time the connection is made. For example, the following code will result in slot() being called 3 times when signal() is emitted once.

connect(obj, SIGNAL(signal()), obj2, SLOT(slot()));
connect(obj, SIGNAL(signal()), obj2, SLOT(slot()));
connect(obj, SIGNAL(signal()), obj2, SLOT(slot()));

如果您在可能運行多次的代碼中進行連接,通常使用 Qt::UniqueConnection 作為第 5 個參數(shù)是個好主意.以下代碼將導致 slot()signal() 發(fā)出一次時被調(diào)用 1 次.

If you are doing connects in code that may be run more than once, it is generally a good idea to use Qt::UniqueConnection as the 5th parameter. The following code will result in slot() being called 1 time when signal() is emitted once.

connect(obj, SIGNAL(signal()), obj2, SLOT(slot()), Qt::UniqueConnection);
connect(obj, SIGNAL(signal()), obj2, SLOT(slot()), Qt::UniqueConnection);
connect(obj, SIGNAL(signal()), obj2, SLOT(slot()), Qt::UniqueConnection);

我猜你的代碼不能正常工作的原因是你省略了第 5 個參數(shù)并且連接默認為 Qt::DirectConnection(對于單線程程序).這會立即調(diào)用插槽,就好像它是一個函數(shù)調(diào)用一樣.這意味著有可能在斷開連接之前再次調(diào)用 connect(如果您的程序中存在循環(huán)).

I'm guessing the reason your code is not working correctly is because you are omitting the 5th parameter and connect defaults to Qt::DirectConnection (for single threaded programs). This immediately calls the slot as if it were a function call. This means that it is possible for connect to be called again before the disconnect happens (if there are loops in your program).

這篇關(guān)于每次發(fā)出信號時都會多次調(diào)用插槽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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++ 中,為什么我不能像這樣編寫 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)形?)
主站蜘蛛池模板: 欧美在线一区二区三区 | 日韩在线免费视频 | 日韩精品 电影一区 亚洲 | 美女福利视频网站 | 国产一级一级毛片 | 成人一区在线观看 | 欧美一卡二卡在线 | 在线一级片 | 国产露脸国语对白在线 | 在线久草| 久久久www成人免费精品 | 亚洲国产中文在线 | 中文一区二区 | 免费在线播放黄色 | 欧美日韩在线视频一区 | 日韩免费毛片视频 | 精品国产一区一区二区三亚瑟 | 久久成人免费视频 | 黄色av网站在线观看 | 伊人爽| 久色激情 | 91五月天| 欧美日韩亚洲视频 | 午夜影院在线免费观看视频 | 欧美日韩国产高清视频 | www.伊人.com | 欧美日韩久久久久 | 久久久久亚洲精品国产 | 99精品视频免费观看 | 中文字幕在线观看视频网站 | 欧美日韩一 | 日韩欧美在线观看一区 | av在线天天 | 国产在线激情视频 | 在线国产一区二区三区 | 日韩黄色av | 天天玩天天操天天干 | 欧美日韩三级 | 国产超碰人人爽人人做人人爱 | 国产精品久久久久久久久污网站 | 精品无码久久久久久国产 |