PDA

View Full Version : focusChanged signal being called numerous times every time I click on a widget?



aondra
24th January 2017, 18:07
EDIT WITH SOLUTION:
The problem was simple. I connected to focusChanged in my custom line edit classes, so for every custom line edit, my slot was being called whenever a focusChanged event came in.

Moderators: feel free to delete this post.


Original post below:

I have an app using QT 5.6.1 that I want to open the Windows Virtual Keyboard if a user clicks on a CustomLineEdit, and close the keyboard if the user clicks anywhere else.

To do this, I have the focusChanged (http://doc.qt.io/qt-4.8/qapplication.html#focusChanged) signal connected to a slot that checks if the "now" widget is a custom line edit, if so it opens the keyboard, if not, it closes the keyboard.

However, I noticed that this was very laggy, so I added a print statement, and here's what I see every time I click on a custom line edit:


FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 00000000 current: 053B4DD0
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00
FocusChanged. previous: 053B4DD0 current: 08964B00


Is there a reason this is being called so many times?

Is there anything I can do short from keeping track of the last time I saw a focusChanged event and filtering duplicates?