#include "mainwindow.h"
#include <QDebug>
#include <thread>
#include <chrono>
// set to connect/disconnect the slot
#define CONNECT_DISCONNECT_FIX 0
// set PROCESS_EVENTS to 0 to not issue QApplication::processEvents();
#define PROCESS_EVENTS 0
// set SLEEP_MILLISECONDS to how long to delay in slot (< 350 seems to work, 2000 is usually guaranteed
#define SLEEP_MILLISECONDS 2000
// show some output
#define DEBUG_OUTPUT(strDescription,bInSlot,nID) qDebug() << (strDescription) << "\n\tID: " << (nID) << "\n\tInSlot: "<< (bInSlot) << "\n\tThreadID: " << _threadid << "\n\tTimeStamp: " << std::chrono::high_resolution_clock::now().time_since_epoch().count() << "\n\n";
MainWindow
::MainWindow(QWidget* parent
) :{
m_UI.setupUi(this);
bool bResult = connect(m_UI.spinBox,SIGNAL(valueChanged(int)),this,SLOT(OnSlotSpinBox(int)),Qt::QueuedConnection);
}
MainWindow::~MainWindow()
{
}
void MainWindow::OnSlotSpinBox(int nValue)
{
#if CONNECT_DISCONNECT_FIX
bool bResult = disconnect(m_UI.spinBox,SIGNAL(valueChanged(int)),this,SLOT(OnSlotSpinBox(int)));
#endif
// unique ID
static uint32_t snID = 0;
// transfer to local, so it is right when re-entrancy occurs
uint32_t nID = ++snID;
static bool sbInSlot = false;
DEBUG_OUTPUT("[enter] OnSlotSpinBox",sbInSlot,nID);
if (!sbInSlot) {
sbInSlot = true;
DEBUG_OUTPUT("[sleep-start] OnSlotSpinBox",sbInSlot,nID);
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
#if PROCESS_EVENTS
DEBUG_OUTPUT("[processEvents-start] OnSlotSpinBox",sbInSlot,nID);
DEBUG_OUTPUT("[processEvents-end] OnSlotSpinBox",sbInSlot,nID);
#endif
DEBUG_OUTPUT("[sleep-end] OnSlotSpinBox",sbInSlot,nID);
sbInSlot = false;
}
else {
DEBUG_OUTPUT("[RE-ENTRANCY DETECTED] OnSlotSpinBox",sbInSlot,nID);
}
DEBUG_OUTPUT("[exit] OnSlotSpinBox",sbInSlot,nID);
#if CONNECT_DISCONNECT_FIX
bResult = connect(m_UI.spinBox,SIGNAL(valueChanged(int)),this,SLOT(OnSlotSpinBox(int)),Qt::QueuedConnection);
#endif
}
#include "mainwindow.h"
#include <QDebug>
#include <thread>
#include <chrono>
// set to connect/disconnect the slot
#define CONNECT_DISCONNECT_FIX 0
// set PROCESS_EVENTS to 0 to not issue QApplication::processEvents();
#define PROCESS_EVENTS 0
// set SLEEP_MILLISECONDS to how long to delay in slot (< 350 seems to work, 2000 is usually guaranteed
#define SLEEP_MILLISECONDS 2000
// show some output
#define DEBUG_OUTPUT(strDescription,bInSlot,nID) qDebug() << (strDescription) << "\n\tID: " << (nID) << "\n\tInSlot: "<< (bInSlot) << "\n\tThreadID: " << _threadid << "\n\tTimeStamp: " << std::chrono::high_resolution_clock::now().time_since_epoch().count() << "\n\n";
MainWindow::MainWindow(QWidget* parent) :
QMainWindow(parent)
{
m_UI.setupUi(this);
bool bResult = connect(m_UI.spinBox,SIGNAL(valueChanged(int)),this,SLOT(OnSlotSpinBox(int)),Qt::QueuedConnection);
}
MainWindow::~MainWindow()
{
}
void MainWindow::OnSlotSpinBox(int nValue)
{
#if CONNECT_DISCONNECT_FIX
bool bResult = disconnect(m_UI.spinBox,SIGNAL(valueChanged(int)),this,SLOT(OnSlotSpinBox(int)));
#endif
// unique ID
static uint32_t snID = 0;
// transfer to local, so it is right when re-entrancy occurs
uint32_t nID = ++snID;
static bool sbInSlot = false;
DEBUG_OUTPUT("[enter] OnSlotSpinBox",sbInSlot,nID);
if (!sbInSlot) {
sbInSlot = true;
DEBUG_OUTPUT("[sleep-start] OnSlotSpinBox",sbInSlot,nID);
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS));
#if PROCESS_EVENTS
DEBUG_OUTPUT("[processEvents-start] OnSlotSpinBox",sbInSlot,nID);
QApplication::processEvents();
DEBUG_OUTPUT("[processEvents-end] OnSlotSpinBox",sbInSlot,nID);
#endif
DEBUG_OUTPUT("[sleep-end] OnSlotSpinBox",sbInSlot,nID);
sbInSlot = false;
}
else {
DEBUG_OUTPUT("[RE-ENTRANCY DETECTED] OnSlotSpinBox",sbInSlot,nID);
}
DEBUG_OUTPUT("[exit] OnSlotSpinBox",sbInSlot,nID);
#if CONNECT_DISCONNECT_FIX
bResult = connect(m_UI.spinBox,SIGNAL(valueChanged(int)),this,SLOT(OnSlotSpinBox(int)),Qt::QueuedConnection);
#endif
}
To copy to clipboard, switch view to plain text mode
Bookmarks