QTest Class Reference

[ QtTest module]

The QTest namespace contains all the functions and declarations that are related to the QTestLib 工具。 更多...

类型

Static Methods


详细描述

The QTest namespace contains all the functions and declarations that are related to the QTestLib 工具。

请参考 QTestLib Manual documentation for information on how to write unit tests.


类型文档编制

QTest.KeyAction

This enum describes possible actions for key handling.

常量 描述
QTest.Press 0 键被按下。
QTest.Release 1 键被释放。
QTest.Click 2 The key is clicked (pressed and released).

QTest.MouseAction

This enum describes possible actions for mouse handling.

常量 描述
QTest.MousePress 0 A mouse button is pressed.
QTest.MouseRelease 1 A mouse button is released.
QTest.MouseClick 2 A mouse button is clicked (pressed and released).
QTest.MouseDClick 3 A mouse button is double clicked (pressed and released twice).
QTest.MouseMove 4 The mouse pointer has moved.

方法文档编制

QTest.keyClick ( QWidget   widget , Qt.Key   key , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

Simulates clicking of key 采用可选 modifier widget 。若 delay is larger than 0, the test will wait for delay 毫秒。

范例:

 QTest.keyClick(myWidget, Qt.Key_Escape);
 QTest.keyClick(myWidget, Qt.Key_Escape, Qt.ShiftModifier, 200);
			

The first example above simulates clicking the escape key on myWidget without any keyboard modifiers and without delay. The second example simulates clicking shift-escape on myWidget with a following 200 ms delay of the test.

另请参阅 QTest.keyClicks ().

QTest.keyClick ( QWidget   widget , str  key , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

这是重载函数。

Simulates clicking of key 采用可选 modifier widget 。若 delay is larger than 0, the test will wait for delay 毫秒。

范例:

 QTest.keyClick(myWidget, 'a');
			

The example above simulates clicking a on myWidget without any keyboard modifiers and without delay of the test.

另请参阅 QTest.keyClicks ().

QTest.keyClicks ( QWidget   widget , QString  sequence , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

Simulates clicking a sequence of keys on a widget . Optionally, a keyboard modifier can be specified as well as a delay (in milliseconds) of the test before each key click.

范例:

 QTest.keyClicks(myWidget, "hello world");
			

The example above simulates clicking the sequence of keys representing "hello world" on myWidget without any keyboard modifiers and without delay of the test.

另请参阅 QTest.keyClick ().

QTest.keyEvent ( KeyAction   action , QWidget   widget , Qt.Key   key , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

Sends a Qt key event to widget with the given key and an associated action . Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event.

QTest.keyEvent ( KeyAction   action , QWidget   widget , str  ascii , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

这是重载函数。

Sends a Qt key event to widget with the given key ascii and an associated action . Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the 事件。

QTest.keyPress ( QWidget   widget , Qt.Key   key , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

Simulates pressing a key 采用可选 modifier widget 。若 delay is larger than 0, the test will wait for delay 毫秒。

注意: At some point you should release the key using keyRelease ().

另请参阅 QTest.keyRelease () 和 QTest.keyClick ().

QTest.keyPress ( QWidget   widget , str  key , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

这是重载函数。

Simulates pressing a key 采用可选 modifier widget 。若 delay is larger than 0, the test will wait for delay 毫秒。

注意: At some point you should release the key using keyRelease ().

另请参阅 QTest.keyRelease () 和 QTest.keyClick ().

QTest.keyRelease ( QWidget   widget , Qt.Key   key , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

Simulates releasing a key 采用可选 modifier widget 。若 delay is larger than 0, the test will wait for delay 毫秒。

另请参阅 QTest.keyPress () 和 QTest.keyClick ().

QTest.keyRelease ( QWidget   widget , str  key , Qt.KeyboardModifiers   modifier  = Qt.NoModifier, int  delay  = -1)

这是重载函数。

Simulates releasing a key 采用可选 modifier widget 。若 delay is larger than 0, the test will wait for delay 毫秒。

另请参阅 QTest.keyClick ().

QTest.mouseClick ( QWidget   widget , Qt.MouseButton   button , Qt.KeyboardModifiers   modifier  = 0, QPoint   pos  = QPoint(), int  delay  = -1)

Simulates clicking a mouse button 采用可选 modifier widget . The position of the click is defined by pos ; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button.

另请参阅 QTest.mousePress () 和 QTest.mouseRelease ().

QTest.mouseDClick ( QWidget   widget , Qt.MouseButton   button , Qt.KeyboardModifiers   modifier  = 0, QPoint   pos  = QPoint(), int  delay  = -1)

Simulates double clicking a mouse button 采用可选 modifier widget . The position of the click is defined by pos ; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before each press and release.

另请参阅 QTest.mouseClick ().

QTest.mouseEvent ( MouseAction   action , QWidget   widget , Qt.MouseButton   button , Qt.KeyboardModifiers   stateKey , QPoint   pos , int  delay  = -1)

QTest.mouseMove ( QWidget   widget , QPoint   pos  = QPoint(), int  delay  = -1)

Moves the mouse pointer to a widget 。若 pos 不是 specified, the mouse pointer moves to the center of the widget. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer.

QTest.mousePress ( QWidget   widget , Qt.MouseButton   button , Qt.KeyboardModifiers   modifier  = 0, QPoint   pos  = QPoint(), int  delay  = -1)

Simulates pressing a mouse button 采用可选 modifier widget . The position is defined by pos ; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before the press.

另请参阅 QTest.mouseRelease () 和 QTest.mouseClick ().

QTest.mouseRelease ( QWidget   widget , Qt.MouseButton   button , Qt.KeyboardModifiers   modifier  = 0, QPoint   pos  = QPoint(), int  delay  = -1)

Simulates releasing a mouse button 采用可选 modifier widget . The position of the release is defined by pos ; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before releasing the button.

另请参阅 QTest.mousePress () 和 QTest.mouseClick ().

QTest.qSleep (int  ms )

Sleeps for ms milliseconds, blocking execution of the test. qSleep() will not do any event processing and leave your test unresponsive. Network communication might time out while sleeping. 使用 qWait () to do non-blocking sleeping.

ms 必须大于 0。

注意: The qSleep() function calls either nanosleep() on unix or Sleep() on windows, so the accuracy of time spent in qSleep() depends on the operating system.

范例:

 QTest.qSleep(250);
			

另请参阅 qWait ().

QTest.qWait (int  ms )

等待 ms milliseconds. While waiting, events will be processed and your test will stay responsive to user interface events or network communication.

范例:

 int i = 0;
 while (myNetworkServerNotResponding() && i++ < 50)
     QTest.qWait(250);
			

The code above will wait until the network server is responding for a maximum of about 12.5 seconds.

另请参阅 QTest.qSleep ().

bool QTest.qWaitForWindowShown ( QWidget   window )

Waits until the window is shown in the screen. This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen. Returns true.

范例:

 QWidget widget;
 widget.show();
 QTest.qWaitForWindowShown(&widget);
			

该函数在 Qt 4.6 引入。