久久久久久久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 ()?環形?)
主站蜘蛛池模板: 成人一区二区三区在线 | 精品乱人伦一区二区三区 | 国产精品久久片 | 妹子干综合 | 免费性视频 | 色综合久久伊人 | 久久国产一区二区三区 | av一区二区三区四区 | 伊人精品国产 | 久久精品成人 | 日韩a在线| 中文字幕黄色大片 | 综合伊人| 亚洲免费观看视频网站 | 精品亚洲国产成av人片传媒 | 黄色精品 | 国产精品免费一区二区三区四区 | 成人小视频在线观看 | 操操操日日日 | 国产精品久久久久久久久大全 | 秋霞a级毛片在线看 | 免费观看av | 欧美多人在线 | 九九免费 | 欧美日韩亚洲一区 | 国产成人精品一区二 | 嫩草视频免费 | 日韩在线欧美 | 亚洲欧美网站 | 一区二区三区av | 欧美日韩亚洲国产 | 亚洲高清成人 | 精品久久久久久 | 久草视频网站 | 婷婷丁香在线视频 | 精品国产一区二区三区日日嗨 | 日韩免费视频一区二区 | 视频一区二区在线观看 | 亚洲视频免费在线观看 | 亚洲欧美一区二区三区国产精品 | 97精品国产97久久久久久免费 |