QKeyPress - 在Qt中模拟按键
QKeyPress - Simulating key press in Qt
如何在Qt中模拟用户交互(按键事件(?
我尝试了相同的方法,但无法写在行编辑小部件上
ui->lineEdit->setFocus();
QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_X, Qt::NoModifier);
QApplication::sendEvent(ui->lineEdit, key_press);
交互
QApplication::postEvent(ui->lineEdit, key_press);
也没有成功。
我也尝试了以下内容,但没有得到任何结果。
QKeyEvent key(QEvent::KeyPress, Qt::Key_X, Qt::NoModifier);
QApplication::sendEvent(ui->lineEdit, &key);
if (key.isAccepted()) {
qDebug()<<"everything is ok";
} else {
qDebug()<<"something wrong";
}
请告诉我我错过了什么。
问候 萨彦
在链接中,您指示输入了输入,因此文本不是必需的,但是如果要发送信件,则必须传递该参数:
ui->lineEdit->setFocus();
QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_X, Qt::NoModifier, "X");
// text ─────┘
QApplication::sendEvent(ui->lineEdit, key_press);
相关文章:
- 模拟GPS数据,以便使用Qt与Traccar一起使用
- QKeyPress - 在Qt中模拟按键
- 在Qt中模拟全局按键
- Qt:模拟来自顶部父小部件的 QMouseButtonPress 事件
- Qt 自动 UI 测试因消息框而停止.如何在消息框中模拟输入?
- 模拟按钮单击qt快速控制按钮
- 如何模拟QT UDP程序的数据包丢失
- Qt测试模拟动态链接库
- 如何为QT快速设计师模拟C 枚举
- Qt的std::unordered_set模拟/对应物
- qInstallMessageHandler() 在 Qt 4.8 中模拟
- 模拟鼠标按钮按QT 5.3仅第一次工作
- 如何用Qt模拟鼠标事件
- 如何在Qt中模拟崩溃
- 如何在Qt-regexp中模拟否定的lookbacking断言
- 在Qt中生成(模拟)假鼠标事件
- Qt/C++:用按钮任意中断QProcess(模拟^C)
- 如何在Linux和Windows上的Qt中模拟所有鼠标和键盘事件
- Qt UI测试:如何使用QTest模拟QMenuBar项上的点击
- 如何存根/模拟Qt类