I am using one signal and slot connection in a block. My code as follows
in 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()));
}
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.
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 whensignal()is emitted once.If you are doing connects in code that may be run more than once, it is generally a good idea to use
Qt::UniqueConnectionas the 5th parameter. The following code will result inslot()being called 1 time whensignal()is emitted once.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).