如何使用C 访问ActiveQt WebBrowser
how to access ActiveQt webbrowser using c++
我已经在一个小部件中使用Active-QT创建了Web-Browser,在第二个小部件中,我正在创建一个虚拟键盘。我必须用虚拟键盘在浏览器的文本框(例如Google搜索框(中写入。我正在使用键盘发送事件方法将键盘事件发送到浏览器,但没有在Web浏览器中编写。当我在第一个小部件中创建了一行编辑并尝试通过相同的虚拟键盘编写,然后它写得完美,但是在浏览器的情况下,它不是写作。因此,我想访问浏览器的HTML内容以获取网站搜索框的ID。因此,我将重点放在该特定ID上。我无助,请帮忙。提前致谢。技术堆栈QT:Active QT组件,QT 5.7.0,QT创建者IDE,带有Min GW和C 。
编辑:测试案例的代码段将单按钮按事件发送到WebBrowser附件,将设计器快照和代码片段发送。在此处输入图像描述
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);
}
在Web浏览器中写入SendInput方法,将人工击键发送到ButtonClick事件上的浏览器,它将适用于每个浏览器。在发送击键之前,您必须在按钮单击按钮时将Web浏览器保持在最新情况。代码片段要在虚拟键上写入WebBrowser:
void Widget::on_pushButton_clicked() {
ui->axWidget->setFocus(); //setting focus of webbrowser
ui->pushButton->setFocusPolicy(Qt::NoFocus);//focus policy of virtual key
//webbrowser on top every time
ui->axWidget->setWindowFlags(Qt::WindowStaysOnTopHint);
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wVk = 0x41;
ip.ki.wScan = 0;
ip.ki.dwFlags = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
// Send the keyboard event to the specified window
SendInput(1, &ip, sizeof(INPUT)); }
此代码是一个示例代码,显示单个虚拟键在Web浏览器上。
相关文章:
- 如何使用ActiveQt在excel中将工作表附加到工作簿末尾
- 为C /CLI中的所有请求添加自定义的标头到WebBrowser控件
- 如何使用C 访问ActiveQt WebBrowser
- 如果不可见,ActiveQT将无法打开 *.xl
- 如何在WebBrowser控件窗口中生成异常.MFC中实现的外部方法
- MFC C++WebBrowser控件从字符串加载HTML
- 隐藏滚动条在WebBrowser控件- MFC
- ActiveQt Com应用程序示例- Com服务器未在Windows注册表中注册(Qt4.7.4)
- 如何干净地销毁WebBrowser控件
- Qt QAxWidget - WebBrowser手动设置插槽/信号