How to cancel pending(unprocessed) emitted signals
-
i have 3 buttons every button is connected by QSIgnalMap;
connect(button, SIGNAL(pressed()), signalMapper, SLOT(map()),Qt::DirectConnection);
connect(signalMapper,SIGNAL(mapped(QObject*)),this,SLOT(setBackground(QObject*)),Qt::DirectConnection);when i clike button1 five times(for instance , button1 is cliked everytime),the result that the button1's slot function is executed five times.how to exeute once button1's slot function ,the rest can't be executed. that's not over,when i go on executing the same Operation ,the result is the same that once solt function is executed ,the rest can't be executed.
-
Have you tried disabling the buttons so that they can't be clicked? This way, you don't need to cancel signals. See my last post at http://qt-project.org/forums/viewthread/34029/P15/
Anyway, you can use QCoreAppication::removePostedEvents() to remove QUEUED signals (Qt::QueuedConnection), but I don't think you can remove DIRECT signals (Qt::DirectConnection).
-
it's no affcet that the button is disabled ,for instance the frist five times, we can prevent the rest solt,but when i want to go on cliking the second five times ,how to do ?
and QCoreAppication::removePostedEvents() is also no effect too.when i use Qt::QueuedConnection.
-
When you do want to prevent that the user can press the button multiple times until the first press isn't handled yet the disabling should do it.
When you don't want that the same button is consecutively pressed multiple times you need to handle this in your application logic.
-
Hi, IMO, all the solutions given by JKSH and raven-worx should works.
You had better given your code(a simple example that can reproduce your problem) if you find that doesn't work for you.