I have a situation where I want to bring up a web page that the user will interact with, and when they click on a submit button a response is sent, and I want to get that response in my Qt program and then destroy the view with the page. I am able to bring up the page like this:
Dialog.resize(1500, 1000);
loginView = new QWebView(&Dialog);
loginView->setObjectName(QStringLiteral("webView"));
loginView->setUrl(QUrl(QStringLiteral("http://foo.bar.com/baz/")));
Dialog.exec();
But I have no idea how I could get the response sent when the user submits the page, nor how I would destroy the page.
Online I found info on doing it like this:
QWebEngineView *view = new QWebEngineView(parent);
view->load(QUrl("http://qt-project.org/"));
view->show();
Or this:
#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());
};
};
Which seem better, but I still don't know how I'd get the response from the page back.
UPDATE: This is what my code currently is:
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????
}