Hi,
I am not sure where to begin. My feeling is, you have a problem with the concept of event-loop, I will get to that in a moment. To clarify: you are wondering, that your event-handler is executed often instead of once?
Concept of Event-Loop. This is your program-entry (??):
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyMainWindow window;
window.show()
return app.exec();
}
“app.exec” enter the “Qt-Mainloop”. This mainloop does something like this:
// Event-Loop:
while (1)
{
waitForEvent();
processEvent();
}
So you see — while an event is being processed, another event cannot be processed, until processing is done and the Event-Loop is reentered.
Assuming that you are using “mouse-clicked”, exactly one event should be fired when you press and then release the mouse-button over your button. Or have you used “press” and “release” signals?
Now the question is, why your event-handler is called more than once. So there have to be multiple events in the queue which trigger your function.
From your code I cannot see, why this is. Have you connected multiple signals to that slot? Can you give more code? Can you set a breakpoint in your handler-function and use the call-stack to find out, which events are triggering it?
Best Regards,
Tobias
↧