英文:
Qt - QTest::keyClick() - is it synchronized to paint?
问题
我有一个GUI,我想要使用QTest
进行测试。
我计划创建一个单独的线程,执行QTest::keyClick()测试步骤,但我想要将我的测试步骤与QWidget::repaint()
同步,也就是说,我希望每个QTest::keyClick()
都发生在前一个QTest::keyClick()
引起的重绘之后(如果有的话)。
QTest::keyClick()
- 来自步骤1的重绘
QTest::keyClick()
- 来自步骤2的重绘
我不希望出现以下情况:
QTest::keyClick()
QTest::keyClick()
- 来自步骤1的重绘
- 来自步骤2的重绘
问题
如何确保keyClick()
不会在上一个keyClick()
的绘图事件之前发生?
英文:
I have a GUI which I want to test with QTest
.
I'm planning on having a separate thread which executes QTest::keyClick() test steps but I want to synchronize my test steps with QWidget::repaint()
i.e. I want each QTest::keyClick()
to happen only after the repaint (if any) caused by the repaint from the previous QTest::keyClick()
QTest::keyClick()
- Repaint from step 1
QTest::keyClick()
- Repaint from step 2
I do not want
QTest::keyClick()
QTest::keyClick()
- Repaint from step 1
- Repaint from step 2
QUESTION
How to make sure keyClick()
s do not occur before paint event from previous keyClick()
?
答案1
得分: 0
不需要同步:每次调用 keyClick()
都会导致调用 qApp->processEvents()
。
static void simulateEvent(QWindow *window, bool press, int code,
Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1)
{
QEvent::Type type;
type = press ? QEvent::KeyPress : QEvent::KeyRelease;
qt_handleKeyEvent(window, type, code, modifier, text, repeat, delay);
qApp->processEvents();
}
这将在下一个 QTest.keyClick()
之前触发任何绘图事件。
英文:
No need for synchronization: each call to keyClick()
results in a call to qApp->processEvents()
static void simulateEvent(QWindow *window, bool press, int code,
Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1)
{
QEvent::Type type;
type = press ? QEvent::KeyPress : QEvent::KeyRelease;
qt_handleKeyEvent(window, type, code, modifier, text, repeat, delay);
qApp->processEvents();
}
which would trigger any paint events before the next QTest.keyClick()
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论