<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QTest Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTest Class Reference<br /><sup><sup>[<a href="qttest.html">QtTest</a> module]</sup></sup></h1><p>The QTest namespace contains all the functions and declarations that are related to the <a href="qtestlib-manual.html#qtestlib">QTestLib</a> tool. <a href="#details">More...</a></p> <h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qtest.html#KeyAction-enum">KeyAction</a></b> { Press, Release, Click }</li><li><div class="fn" />enum <b><a href="qtest.html#MouseAction-enum">MouseAction</a></b> { MousePress, MouseRelease, MouseClick, MouseDClick, MouseMove }</li></ul><h3>Static Methods</h3><ul><li><div class="fn" /><b><a href="qtest.html#keyClick">keyClick</a></b> (QWidget <i>widget</i>, Qt.Key <i>key</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyClick-2">keyClick</a></b> (QWidget <i>widget</i>, str <i>key</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyClicks">keyClicks</a></b> (QWidget <i>widget</i>, QString <i>sequence</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyEvent">keyEvent</a></b> (KeyAction <i>action</i>, QWidget <i>widget</i>, Qt.Key <i>key</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyEvent-2">keyEvent</a></b> (KeyAction <i>action</i>, QWidget <i>widget</i>, str <i>ascii</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyPress">keyPress</a></b> (QWidget <i>widget</i>, Qt.Key <i>key</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyPress-2">keyPress</a></b> (QWidget <i>widget</i>, str <i>key</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyRelease">keyRelease</a></b> (QWidget <i>widget</i>, Qt.Key <i>key</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#keyRelease-2">keyRelease</a></b> (QWidget <i>widget</i>, str <i>key</i>, Qt.KeyboardModifiers <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#mouseClick">mouseClick</a></b> (QWidget <i>widget</i>, Qt.MouseButton <i>button</i>, Qt.KeyboardModifiers <i>modifier</i> = 0, QPoint <i>pos</i> = QPoint(), int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#mouseDClick">mouseDClick</a></b> (QWidget <i>widget</i>, Qt.MouseButton <i>button</i>, Qt.KeyboardModifiers <i>modifier</i> = 0, QPoint <i>pos</i> = QPoint(), int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#mouseEvent">mouseEvent</a></b> (MouseAction <i>action</i>, QWidget <i>widget</i>, Qt.MouseButton <i>button</i>, Qt.KeyboardModifiers <i>stateKey</i>, QPoint <i>pos</i>, int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#mouseMove">mouseMove</a></b> (QWidget <i>widget</i>, QPoint <i>pos</i> = QPoint(), int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#mousePress">mousePress</a></b> (QWidget <i>widget</i>, Qt.MouseButton <i>button</i>, Qt.KeyboardModifiers <i>modifier</i> = 0, QPoint <i>pos</i> = QPoint(), int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#mouseRelease">mouseRelease</a></b> (QWidget <i>widget</i>, Qt.MouseButton <i>button</i>, Qt.KeyboardModifiers <i>modifier</i> = 0, QPoint <i>pos</i> = QPoint(), int <i>delay</i> = -1)</li><li><div class="fn" /><b><a href="qtest.html#qSleep">qSleep</a></b> (int <i>ms</i>)</li><li><div class="fn" /><b><a href="qtest.html#qWait">qWait</a></b> (int <i>ms</i>)</li><li><div class="fn" />bool <b><a href="qtest.html#qWaitForWindowShown">qWaitForWindowShown</a></b> (QWidget <i>window</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTest namespace contains all the functions and declarations that are related to the <a href="qtestlib-manual.html#qtestlib">QTestLib</a> tool.</p> <p>Please refer to the <a href="qtestlib-manual.html">QTestLib Manual</a> documentation for information on how to write unit tests.</p> <hr /><h2>Type Documentation</h2><h3 class="fn"><a name="KeyAction-enum" />QTest.KeyAction</h3><p>This enum describes possible actions for key handling.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QTest.Press</tt></td> <td class="topAlign"><tt>0</tt></td> <td class="topAlign">The key is pressed.</td> </tr> <tr> <td class="topAlign"><tt>QTest.Release</tt></td> <td class="topAlign"><tt>1</tt></td> <td class="topAlign">The key is released.</td> </tr> <tr> <td class="topAlign"><tt>QTest.Click</tt></td> <td class="topAlign"><tt>2</tt></td> <td class="topAlign">The key is clicked (pressed and released).</td> </tr> </table> <h3 class="fn"><a name="MouseAction-enum" />QTest.MouseAction</h3><p>This enum describes possible actions for mouse handling.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QTest.MousePress</tt></td> <td class="topAlign"><tt>0</tt></td> <td class="topAlign">A mouse button is pressed.</td> </tr> <tr> <td class="topAlign"><tt>QTest.MouseRelease</tt></td> <td class="topAlign"><tt>1</tt></td> <td class="topAlign">A mouse button is released.</td> </tr> <tr> <td class="topAlign"><tt>QTest.MouseClick</tt></td> <td class="topAlign"><tt>2</tt></td> <td class="topAlign">A mouse button is clicked (pressed and released).</td> </tr> <tr> <td class="topAlign"><tt>QTest.MouseDClick</tt></td> <td class="topAlign"><tt>3</tt></td> <td class="topAlign">A mouse button is double clicked (pressed and released twice).</td> </tr> <tr> <td class="topAlign"><tt>QTest.MouseMove</tt></td> <td class="topAlign"><tt>4</tt></td> <td class="topAlign">The mouse pointer has moved.</td> </tr> </table> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="keyClick" />QTest.keyClick (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#Key-enum">Qt.Key</a> <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>Simulates clicking of <i>key</i> with an optional <i>modifier</i> on a <i>widget</i>. If <i>delay</i> is larger than 0, the test will wait for <i>delay</i> milliseconds.</p> <p>Examples:</p> <pre class="cpp"> <span class="type"><a href="qtest.html">QTest</a></span><span class="operator">.</span>keyClick(myWidget<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>Key_Escape); <span class="type"><a href="qtest.html">QTest</a></span><span class="operator">.</span>keyClick(myWidget<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>Key_Escape<span class="operator">,</span> <span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>ShiftModifier<span class="operator">,</span> <span class="number">200</span>); </pre> <p>The first example above simulates clicking the <tt>escape</tt> key on <tt>myWidget</tt> without any keyboard modifiers and without delay. The second example simulates clicking <tt>shift-escape</tt> on <tt>myWidget</tt> with a following 200 ms delay of the test.</p> <p><b>See also</b> <a href="qtest.html#keyClicks">QTest.keyClicks</a>().</p> <h3 class="fn"><a name="keyClick-2" />QTest.keyClick (<a href="qwidget.html">QWidget</a> <i>widget</i>, str <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>This is an overloaded function.</p> <p>Simulates clicking of <i>key</i> with an optional <i>modifier</i> on a <i>widget</i>. If <i>delay</i> is larger than 0, the test will wait for <i>delay</i> milliseconds.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qtest.html">QTest</a></span><span class="operator">.</span>keyClick(myWidget<span class="operator">,</span> <span class="char">'a'</span>); </pre> <p>The example above simulates clicking <tt>a</tt> on <tt>myWidget</tt> without any keyboard modifiers and without delay of the test.</p> <p><b>See also</b> <a href="qtest.html#keyClicks">QTest.keyClicks</a>().</p> <h3 class="fn"><a name="keyClicks" />QTest.keyClicks (<a href="qwidget.html">QWidget</a> <i>widget</i>, QString <i>sequence</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>Simulates clicking a <i>sequence</i> of keys on a <i>widget</i>. Optionally, a keyboard <i>modifier</i> can be specified as well as a <i>delay</i> (in milliseconds) of the test before each key click.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qtest.html">QTest</a></span><span class="operator">.</span>keyClicks(myWidget<span class="operator">,</span> <span class="string">"hello world"</span>); </pre> <p>The example above simulates clicking the sequence of keys representing "hello world" on <tt>myWidget</tt> without any keyboard modifiers and without delay of the test.</p> <p><b>See also</b> <a href="qtest.html#keyClick">QTest.keyClick</a>().</p> <h3 class="fn"><a name="keyEvent" />QTest.keyEvent (<a href="qtest.html#KeyAction-enum">KeyAction</a> <i>action</i>, <a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#Key-enum">Qt.Key</a> <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>Sends a Qt key event to <i>widget</i> with the given <i>key</i> and an associated <i>action</i>. Optionally, a keyboard <i>modifier</i> can be specified, as well as a <i>delay</i> (in milliseconds) of the test before sending the event.</p> <h3 class="fn"><a name="keyEvent-2" />QTest.keyEvent (<a href="qtest.html#KeyAction-enum">KeyAction</a> <i>action</i>, <a href="qwidget.html">QWidget</a> <i>widget</i>, str <i>ascii</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>This is an overloaded function.</p> <p>Sends a Qt key event to <i>widget</i> with the given key <i>ascii</i> and an associated <i>action</i>. Optionally, a keyboard <i>modifier</i> can be specified, as well as a <i>delay</i> (in milliseconds) of the test before sending the event.</p> <h3 class="fn"><a name="keyPress" />QTest.keyPress (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#Key-enum">Qt.Key</a> <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>Simulates pressing a <i>key</i> with an optional <i>modifier</i> on a <i>widget</i>. If <i>delay</i> is larger than 0, the test will wait for <i>delay</i> milliseconds.</p> <p><b>Note:</b> At some point you should release the key using <a href="qtest.html#keyRelease">keyRelease</a>().</p> <p><b>See also</b> <a href="qtest.html#keyRelease">QTest.keyRelease</a>() and <a href="qtest.html#keyClick">QTest.keyClick</a>().</p> <h3 class="fn"><a name="keyPress-2" />QTest.keyPress (<a href="qwidget.html">QWidget</a> <i>widget</i>, str <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>This is an overloaded function.</p> <p>Simulates pressing a <i>key</i> with an optional <i>modifier</i> on a <i>widget</i>. If <i>delay</i> is larger than 0, the test will wait for <i>delay</i> milliseconds.</p> <p><b>Note:</b> At some point you should release the key using <a href="qtest.html#keyRelease">keyRelease</a>().</p> <p><b>See also</b> <a href="qtest.html#keyRelease">QTest.keyRelease</a>() and <a href="qtest.html#keyClick">QTest.keyClick</a>().</p> <h3 class="fn"><a name="keyRelease" />QTest.keyRelease (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#Key-enum">Qt.Key</a> <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>Simulates releasing a <i>key</i> with an optional <i>modifier</i> on a <i>widget</i>. If <i>delay</i> is larger than 0, the test will wait for <i>delay</i> milliseconds.</p> <p><b>See also</b> <a href="qtest.html#keyPress">QTest.keyPress</a>() and <a href="qtest.html#keyClick">QTest.keyClick</a>().</p> <h3 class="fn"><a name="keyRelease-2" />QTest.keyRelease (<a href="qwidget.html">QWidget</a> <i>widget</i>, str <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = Qt.NoModifier, int <i>delay</i> = -1)</h3><p>This is an overloaded function.</p> <p>Simulates releasing a <i>key</i> with an optional <i>modifier</i> on a <i>widget</i>. If <i>delay</i> is larger than 0, the test will wait for <i>delay</i> milliseconds.</p> <p><b>See also</b> <a href="qtest.html#keyClick">QTest.keyClick</a>().</p> <h3 class="fn"><a name="mouseClick" />QTest.mouseClick (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#MouseButton-enum">Qt.MouseButton</a> <i>button</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = 0, <a href="qpoint.html">QPoint</a> <i>pos</i> = QPoint(), int <i>delay</i> = -1)</h3><p>Simulates clicking a mouse <i>button</i> with an optional <i>modifier</i> on a <i>widget</i>. The position of the click is defined by <i>pos</i>; the default position is the center of the widget. If <i>delay</i> is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button.</p> <p><b>See also</b> <a href="qtest.html#mousePress">QTest.mousePress</a>() and <a href="qtest.html#mouseRelease">QTest.mouseRelease</a>().</p> <h3 class="fn"><a name="mouseDClick" />QTest.mouseDClick (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#MouseButton-enum">Qt.MouseButton</a> <i>button</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = 0, <a href="qpoint.html">QPoint</a> <i>pos</i> = QPoint(), int <i>delay</i> = -1)</h3><p>Simulates double clicking a mouse <i>button</i> with an optional <i>modifier</i> on a <i>widget</i>. The position of the click is defined by <i>pos</i>; the default position is the center of the widget. If <i>delay</i> is specified, the test will wait for the specified amount of milliseconds before each press and release.</p> <p><b>See also</b> <a href="qtest.html#mouseClick">QTest.mouseClick</a>().</p> <h3 class="fn"><a name="mouseEvent" />QTest.mouseEvent (<a href="qtest.html#MouseAction-enum">MouseAction</a> <i>action</i>, <a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#MouseButton-enum">Qt.MouseButton</a> <i>button</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>stateKey</i>, <a href="qpoint.html">QPoint</a> <i>pos</i>, int <i>delay</i> = -1)</h3><h3 class="fn"><a name="mouseMove" />QTest.mouseMove (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qpoint.html">QPoint</a> <i>pos</i> = QPoint(), int <i>delay</i> = -1)</h3><p>Moves the mouse pointer to a <i>widget</i>. If <i>pos</i> is not specified, the mouse pointer moves to the center of the widget. If a <i>delay</i> (in milliseconds) is given, the test will wait before moving the mouse pointer.</p> <h3 class="fn"><a name="mousePress" />QTest.mousePress (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#MouseButton-enum">Qt.MouseButton</a> <i>button</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = 0, <a href="qpoint.html">QPoint</a> <i>pos</i> = QPoint(), int <i>delay</i> = -1)</h3><p>Simulates pressing a mouse <i>button</i> with an optional <i>modifier</i> on a <i>widget</i>. The position is defined by <i>pos</i>; the default position is the center of the widget. If <i>delay</i> is specified, the test will wait for the specified amount of milliseconds before the press.</p> <p><b>See also</b> <a href="qtest.html#mouseRelease">QTest.mouseRelease</a>() and <a href="qtest.html#mouseClick">QTest.mouseClick</a>().</p> <h3 class="fn"><a name="mouseRelease" />QTest.mouseRelease (<a href="qwidget.html">QWidget</a> <i>widget</i>, <a href="qt.html#MouseButton-enum">Qt.MouseButton</a> <i>button</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifier</i> = 0, <a href="qpoint.html">QPoint</a> <i>pos</i> = QPoint(), int <i>delay</i> = -1)</h3><p>Simulates releasing a mouse <i>button</i> with an optional <i>modifier</i> on a <i>widget</i>. The position of the release is defined by <i>pos</i>; the default position is the center of the widget. If <i>delay</i> is specified, the test will wait for the specified amount of milliseconds before releasing the button.</p> <p><b>See also</b> <a href="qtest.html#mousePress">QTest.mousePress</a>() and <a href="qtest.html#mouseClick">QTest.mouseClick</a>().</p> <h3 class="fn"><a name="qSleep" />QTest.qSleep (int <i>ms</i>)</h3><p>Sleeps for <i>ms</i> 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. Use <a href="qtest.html#qWait">qWait</a>() to do non-blocking sleeping.</p> <p><i>ms</i> must be greater than 0.</p> <p><b>Note:</b> The qSleep() function calls either <tt>nanosleep()</tt> on unix or <tt>Sleep()</tt> on windows, so the accuracy of time spent in qSleep() depends on the operating system.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qtest.html">QTest</a></span><span class="operator">.</span>qSleep(<span class="number">250</span>); </pre> <p><b>See also</b> <a href="qtest.html#qWait">qWait</a>().</p> <h3 class="fn"><a name="qWait" />QTest.qWait (int <i>ms</i>)</h3><p>Waits for <i>ms</i> milliseconds. While waiting, events will be processed and your test will stay responsive to user interface events or network communication.</p> <p>Example:</p> <pre class="cpp"> <span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; <span class="keyword">while</span> (myNetworkServerNotResponding() <span class="operator">&</span><span class="operator">&</span> i<span class="operator">+</span><span class="operator">+</span> <span class="operator"><</span> <span class="number">50</span>) <span class="type"><a href="qtest.html">QTest</a></span><span class="operator">.</span>qWait(<span class="number">250</span>); </pre> <p>The code above will wait until the network server is responding for a maximum of about 12.5 seconds.</p> <p><b>See also</b> <a href="qtest.html#qSleep">QTest.qSleep</a>().</p> <h3 class="fn"><a name="qWaitForWindowShown" />bool QTest.qWaitForWindowShown (<a href="qwidget.html">QWidget</a> <i>window</i>)</h3><p>Waits until the <i>window</i> 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.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qwidget.html">QWidget</a></span> widget; widget<span class="operator">.</span>show(); <span class="type"><a href="qtest.html">QTest</a></span><span class="operator">.</span>qWaitForWindowShown(<span class="operator">&</span>widget); </pre> <p>This function was introduced in Qt 4.6.</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>