0

我有一种情况,我想调出一个用户将与之交互的网页,当他们单击提交按钮时,会发送一个响应,我想在我的 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????
}
4

0 回答 0