Simulate mouse click using Qt Test Lib

You have several ways to simulate mouse events in a Qt application. First, you can create and post mouse events using native functions like:

QMouseEvent eve(...);

qApp->sendEvent(this , &eve);

Second, in QWebView, you can emulate the mouse action using javascript.

Third, you can use QTest lib for mouse emulation. The official tutorial is good. But you should include the correct include headers:

#include <QtTest/QtTest>
#include <qtest_widgets.h>

Just include <QtTest/QtTest> is not enough, you may get the following errors:

error: ‘mouseClick’ is not a member of ‘QTest’

error: ‘keyClicks’ is not a member of ‘QTest’

Note that QTest is a namespace, not a class.

The include directories should have …mingw482_32\include\QtTest, and also you should add “-lQt5Test” to your compiling command.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Comments are closed, but trackbacks and pingbacks are open.