Qt 5.10 Book Examples
chapter16
EventSimulation
main.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// main.cpp
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#include <QtWidgets>
12
13
// ----------------------------------------------------------------------
14
int
main
(
int
argc,
char
** argv)
15
{
16
QApplication app (argc, argv);
17
18
QLineEdit txt(
"User input: "
);
19
txt.show();
20
txt.resize(300, 20);
21
22
int
i;
23
for
(i = 0; i < Qt::Key_Z - Qt::Key_A + 1; ++i) {
24
QChar ch = 65 + i;
25
int
nKey = Qt::Key_A + i;
26
QKeyEvent keyPress(QEvent::KeyPress, nKey, Qt::NoModifier, ch);
27
QApplication::sendEvent(&txt, &keyPress);
28
29
QKeyEvent keyRelease(QEvent::KeyRelease, nKey, Qt::NoModifier, ch);
30
QApplication::sendEvent(&txt, &keyRelease);
31
}
32
33
return
app.exec();
34
}
35
main
int main(int argc, char **argv)
Definition:
main.cpp:15
Generated by
1.8.14