简体   繁体   English

在squishtest中使用Qt事件处理程序

[英]Using Qt Event Handlers in squishtest

I'm using squishtest library for manipulating Qt application from my Python code and attempting to use event handlers as follows: 我正在使用squishtest库从我的Python代码处理Qt应用程序,并尝试使用事件处理程序,如下所示:

import squishtest


def handle_mouse_event(event):
    print 'Clicked!'


squishtest.startApplication('application')
squishtest.installEventHandler('QMouseEvent', handle_mouse_event)

Unfortunately this doesn't work, ie nothing happens on clicking elements inside the app, however it works in case I run equivalent of this code inside the Squish IDE in Squish runtime: 不幸的是,这不起作用,即在应用程序内单击元素没有任何反应,但是如果我在Squish运行时中的Squish IDE中运行了与该代码等效的代码,它将起作用:

import squish


def handle_mouse_event(event):
    print 'Clicked!'


squish.startApplication('application')
squish.installEventHandler('QMouseEvent', handle_mouse_event)

What is the difference and how to get event handlers working with squishtest ? 有什么区别,以及如何使事件处理程序与squishtest一起使用?

Python 2.7.14, Squish 6.3.1, Ubuntu 16.04 Python 2.7.14,Squish 6.3.1,Ubuntu 16.04

(Reposting as answer as suggested by original poster.) (按照原始海报的建议重新张贴作为答案。)

This works for me on Linux and Windows with Squish 6.3.x+, using the Python installation in the Squish package - but admittedly I have added a snooze(5) at the end of the script to have some time to "mouse around" over the application's window, then even the mouse movement based events trigger execution of the event handler function. 在Squish软件包中使用Python安装,此版本在使用Squish 6.3.x +的Linux和Windows上对我有效-但坦率地说,我在脚本末尾添加了snooze(5),以便有一些时间可以在应用程序的窗口,然后甚至基于鼠标移动的事件也会触发事件处理函数的执行。

Another side effect of using snooze() is that the event loops keep being spun, which is not the case when using time.sleep() (which you later mentioned to have used before). 使用snooze()的另一个副作用是事件循环一直处于旋转状态,而使用time.sleep()则不是这种情况(您稍后提到过)。

If it still does not work for you I recommend to contact the technical support of froglogic Squish. 如果仍然无法解决问题,建议您与froglogic Squish的技术支持联系。

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

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