简体   繁体   中英

QTimer timeout() method no longer firing after code restructure

I recently reformatted some of my code to be more readable. I had code in my MainWindow class to handle touch events. Among these functions was a pinchZoom function, which was working prior to my changes. I moved the code instead to a singleton class which is a QObject.

When the pinchZoom is detected, the relevant widget (found by QApplication::widgetAt()) calls its pinchZoom() method, which stops and then restarts a single-shot QTimer. The QTimer's timeout() method is connected to a slot which does the actual zooming and updating the view. This is so I can add a delay between the actual pinch-zoom gesture and the view update.

Prior to moving my code, this timeout() signal worked just fine and the zoom method was triggered. However, despite not touching the signal/slot connections, the zoom slot triggered by the timeout() method no longer gets called. The actual connection between the timeout() signal and the slot is done in the constructor of the widget where the timer lives.

I have checked, and the signal/slot connection is returning true, so the connection IS there.

Is there some reason why this would happen? Does it have to do with the fact that the QTimer being started is happening within a singleton class now instead of the MainWindow class?

Seems the issue was that my singleton class is on a separate thread, and the QTimer couldn't be triggered from a separate thread. I just set up a slot in the original MainWindow class to accept a signal from the singleton class to then call the pinch zoom method. Works fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM