Bug #7481
Having a long running command with a processEvents() call in it together with a timer can result in clicked events being processed too many times
Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
03/05/2020
Due date:
% Done:
0%
Estimated time:
Description
I hava attached an MWE here.
What happened:
- Running the program
- Clicked the button which resulted in the output "Clicked: 0"
- Clicked the button again which resulted in the output "Clicked: 1" and on a new line "Clicked: 2"
What I expected to happen:
- Running the program
- Clicked the button which resulted in the output "Clicked: 0"
- Clicked the button again which resulted only in the output "Clicked: 1"
In short, it seems that when there is a timer in the application the clicked event gets processed one time too many when clicked the second time.
Not starting the timer results in the expected output.
#include <Wt/WApplication> #include <Wt/WPushButton> #include <Wt/WTimer> #include <stdio.h> class Application : public Wt::WApplication { private: int count = 0; public: Application(const Wt::WEnvironment& env) : Wt::WApplication(env) { auto updateTimer = new Wt::WTimer(root()); updateTimer->setInterval(100); #if 1 // If this block is enabled, the issue exists updateTimer->start(); #endif auto testButton = new Wt::WPushButton("Test", root()); testButton->clicked().connect(std::bind([this]() { std::cout << "Clicked: " << this->count++ << std::endl; // Don't do anything if the button is clicked more than once if (this->count > 1) { return; } while (this->count <= 1) { // Simulate long running command for the first click // Exit when the button has been clicked again WApplication::instance()->processEvents(); usleep(500000); } })); } }; Wt::WApplication* createApplication(const Wt::WEnvironment& env) { return new Application(env); } int main(int argc, char **argv) { return Wt::WRun(argc, argv, &createApplication); }
No data to display