我有一种情况,我想提出一个用户将与之交互的网页,当他们点击提交按钮时,会发送响应,我想在我的Qt程序中获得该响应,然后销毁页面视图。我可以像这样显示页面:
Dialog.resize(1500, 1000);
loginView = new QWebView(&Dialog);
loginView->setObjectName(QStringLiteral("webView"));
loginView->setUrl(QUrl(QStringLiteral("http://foo.bar.com/baz/")));
Dialog.exec();
但是我不知道如何在用户时收到响应 提交页面,也不会破坏页面。
在线我发现了这样做的信息:
QWebEngineView *view = new QWebEngineView(parent);
view->load(QUrl("http://qt-project.org/"));
view->show();
或者这个:
#include"myWebView.h"
int main(int argc,char** argv)
{
QApplication app(argc,argv);
myWebView* view = new myWebView();
view->load(QUrl("http://www.google.co.uk"));
view->resize(500,500);
view->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
view->show();
return app.exec();
}
#include <QtWebKit>
#include <QtGui>
class myWebView:public QWebView
{
Q_OBJECT
public:
myWebView():QWebView()
{
connect(this,SIGNAL(linkClicked(QUrl)),this,SLOT(linkClicked(QUrl)));
};
~myWebView()
{};
private slots:
void linkClicked(QUrl url)
{
QMessageBox::information(this,"Hello!","You Clicked: \n"+url.toString());
};
};
哪个看起来更好,但我仍然不知道我是如何从页面获得回复的。
更新:这是我目前的代码:
void cap::userLoginStatusButton_clicked()
{
loginDialog = new QDialog();
loginDialog->resize(1500, 1000);
loginView = new QWebView(loginDialog);
loginView->setObjectName(QStringLiteral("webView"));
loginView->setUrl(QUrl(QStringLiteral("http://foo.bar.com/baz/")));
connect(loginView, SIGNAL(urlChanged(QUrl)), this, SLOT(loginCompleted(QUrl)));
loginDialog->exec();
}
void cap::loginCompleted(QUrl url)
{
// here is where I am stuck - how do I get the JSON returned from http://foo.bar.com/baz/ here????
}