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

每次發出信號時都會多次調用插槽

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

問題描述

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

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 語句執行時,在get() 函數中,槽被調用了很多次.根據我的說法,它應該只調用一次.

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.

推薦答案

正如一些評論中所述,這通常是由于多次調用 connect 造成的.每次建立連接時都會調用一次插槽.例如,下面的代碼將導致 slot()signal() 被發射一次時被調用 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 個參數是個好主意.以下代碼將導致 slot()signal() 發出一次時被調用 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 個參數并且連接默認為 Qt::DirectConnection(對于單線程程序).這會立即調用插槽,就好像它是一個函數調用一樣.這意味著有可能在斷開連接之前再次調用 connect(如果您的程序中存在循環).

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).

這篇關于每次發出信號時都會多次調用插槽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 ()?環形?)
主站蜘蛛池模板: 96精品| 中文字幕麻豆 | 五月婷婷丁香 | 超碰777 | 亚洲成人a v | 欧美精品久久久久久 | 伊人春色av | 日韩性视频| 亚洲激情第一页 | 日韩精品国产一区 | 四虎4hu永久免费网站影院 | 国产三级视频 | av播播| 成人影| 一区二区三区在线观看视频 | 成人午夜激情视频 | 亚洲国产区 | 日韩大片在线观看 | 国产一区二区三区在线 | 欧美精品久久久久久久多人混战 | 黄色免费小视频 | 中文在线观看视频 | 国产成人精品视频 | 亚洲日本天堂 | 国产精品一区二区三区不卡 | 青青操影院| 精品综合网 | 国产亚洲一区二区三区 | 日本一级做a爱片 | 伊久久 | 久久精品欧美一区二区三区不卡 | 波多野结衣乳巨码无在线观看 | 欧美性猛交99久久久久99按摩 | 最新中文字幕在线观看 | 亚洲午夜av | 99香蕉视频 | 亚欧洲精品在线视频免费观看 | 欧美一级淫片免费视频黄 | 四虎成人在线 | 久久九九视频 | 国产com|