我在一个小部件中使用Active-qt创建了Web浏览器,在第二个小部件中我创建了一个虚拟键盘。我必须写在浏览器的文本框(例如谷歌搜索框)与虚拟键盘。我正在使用键盘发送事件的方法将按键事件发送到浏览器,但它不能在web浏览器中写入。当我在第一个小部件中创建了行编辑,并尝试通过相同的虚拟键盘编写时,它可以完美地写入,但在浏览器中它不能写入。所以我想访问浏览器的HTML内容来获取网站搜索框的id。所以我把焦点设置在那个特定的Id上。我很无助,请帮帮忙。提前谢谢。技术栈QT:Active Qt component,Qt 5.7.0,Qt creator IDE with Min Gw和c++。
编辑:测试用例的代码片段,将单键按下事件发送到well浏览器,附加designer snap以及代码片段。enter image description here
UseKeyBoardDialog::UseKeyBoardDialog(QWidget *parent) : QDialog(parent)
{
setupUi(this);
WebBrowser->setControl("8856F961-340A-11D0-A96B-00C04FD705A2");
QString htmlDoc = WebBrowser->generateDocumentation();
QString outputFilename = "Results.html";
QFile outputFile(outputFilename);
outputFile.open(QIODevice::WriteOnly);
/* Check it opened OK */
if(!outputFile.isOpen()){
qDebug() << "- Error, unable to open" << outputFilename << "for output";
}
/* Point a QTextStream object at the file */
QTextStream outStream(&outputFile);
/* Write the line to the file */
outStream << htmlDoc;
/* Close the file */
outputFile.close();
//qDebug()<<"htmlDoc "<<htmlDoc;
}
void UseKeyBoardDialog::navigate(const QString &url)
{
WebBrowser->dynamicCall("Navigate(const QString&)", url);
}
void UseKeyBoardDialog::on_pushButton_clicked()
{
// lineEdit->setFocus();
WebBrowser->setFocus();
keybd_event( 0,
0x1E,
KEYEVENTF_SCANCODE| 0,
0 );
// Simulate a key release
keybd_event( 0,
0x1E,
KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE,
0);
}https://stackoverflow.com/questions/44406699
复制相似问题