简体   繁体   English

代码重组后不再触发QTimer timeout()方法

[英]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. 我在MainWindow类中有代码可以处理触摸事件。 Among these functions was a pinchZoom function, which was working prior to my changes. 在这些功能中,有一个pinchZoom功能,该功能在我进行更改之前就可以使用。 I moved the code instead to a singleton class which is a QObject. 我将代码移到了一个单例类(即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. 当检测到pinchZoom时,相关的小部件(由QApplication :: widgetAt()找到)调用其pinchZoom()方法,该方法将停止然后重新启动单次QTimer。 The QTimer's timeout() method is connected to a slot which does the actual zooming and updating the view. QTimer的timeout()方法连接到一个插槽,该插槽可以实际缩放和更新视图。 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. 在移动代码之前,此timeout()信号工作得很好,并且触发了zoom方法。 However, despite not touching the signal/slot connections, the zoom slot triggered by the timeout() method no longer gets called. 但是,尽管未触及信号/插槽连接,但不再调用由timeout()方法触发的缩放插槽。 The actual connection between the timeout() signal and the slot is done in the constructor of the widget where the timer lives. timeout()信号和插槽之间的实际连接是在计时器所在的小部件的构造函数中完成的。

I have checked, and the signal/slot connection is returning true, so the connection IS there. 我已经检查过,并且信号/插槽连接返回的是true,所以连接在那里。

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? 它是否与正在启动QTimer的事件现在在单例类而不是MainWindow类中发生有关?

Seems the issue was that my singleton class is on a separate thread, and the QTimer couldn't be triggered from a separate thread. 似乎问题出在我的单例类在单独的线程上,并且QTimer无法从单独的线程触发。 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. 我只是在原始MainWindow类中设置了一个插槽,以接受来自单例类的信号,然后调用捏缩放方法。 Works fine now. 现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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