Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. [Solved] QNetWorkRequest
Forum Updated to NodeBB v4.3 + New Features

[Solved] QNetWorkRequest

Scheduled Pinned Locked Moved Qt WebKit
4 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brcontainer
    wrote on 23 Jul 2013, 13:48 last edited by
    #1

    In Google Chrome, when an error occurs in the request to the server, the Google Chrome tries a new request, see LOG wireshark:

    !http://i.stack.imgur.com/qy0jL.png(wireshark log)!

    I'm developing a full browser in QT and realized that if a request fails the "QWebView" has the same behavior as Google Chrome.

    How can I reimplement the QNetWorkRequest/QNetWorkAccessManager to work like the conventional browsers?

    Help me please.

    @myWebPage *myWP = new myWebPage();
    myWP->setForwardUnsupportedContent(true);
    myWP->setNetworkAccessManager(m_network);
    ui->myWebView->setPage(myWP);

    if(q!=true) {
    settings = QWebSettings::globalSettings();

    settings->setAttribute( QWebSettings::OfflineWebApplicationCacheEnabled,true );
    settings->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls,true );
    settings->setAttribute( QWebSettings::OfflineStorageDatabaseEnabled,true );
    settings->setAttribute( QWebSettings::LocalContentCanAccessFileUrls,true );
    settings->setAttribute( QWebSettings::LocalStorageEnabled,true );
    settings->setAttribute( QWebSettings::JavascriptCanOpenWindows,true );
    settings->setAttribute( QWebSettings::JavascriptCanCloseWindows,true );
    settings->setAttribute( QWebSettings::JavascriptEnabled,true );
    
    settings->setAttribute( QWebSettings::PluginsEnabled,true );
    settings->setAttribute( QWebSettings::JavaEnabled,false );//Desabilita java
    settings->setAttribute( QWebSettings::DeveloperExtrasEnabled,true );
    settings->setAttribute( QWebSettings::AutoLoadImages, true );
    
    
    settings->setAttribute( QWebSettings::DnsPrefetchEnabled, true );
    settings->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true );
    settings->setAttribute( QWebSettings::AcceleratedCompositingEnabled, true );
    settings->setAttribute( QWebSettings::JavascriptCanAccessClipboard, false );
    settings->setAttribute( QWebSettings::ScrollAnimatorEnabled, true );
    
    settings->setAttribute( QWebSettings::PrintElementBackgrounds, false );
    
    settings->setOfflineWebApplicationCachePath( QString(localStorage+"/appcache") );
    settings->enablePersistentStorage( QString(localStorage+"/persistent") );
    settings->setOfflineStoragePath( QString(localStorage+"/offlinestorage") );
    settings->setLocalStoragePath( QString(localStorage+"/storage") );
    settings->setIconDatabasePath( QString(localStorage+"/icons") );
    
    settings->setMaximumPagesInCache( 99999 );
    settings->setObjectCacheCapacities( 0,99999,99999 );
    
    settings->setOfflineWebApplicationCacheQuota( 5*1024*1024 );
    settings->setOfflineStorageDefaultQuota( 5*1024*1024 );
    

    }
    connect(ui->myWebView->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(Download(QNetworkRequest)));
    connect(ui->myWebView->page(), SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(unsupportedToDownload(QNetworkReply*)));
    connect(ui->myWebView->page(), SIGNAL(printRequested(QWebFrame*)), this, SLOT(printFrame(QWebFrame*)));@

    QT project: https://github.com/brcontainer/qt-helper

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 26 Jul 2013, 14:06 last edited by
      #2

      i don't know if there is a setting for retry on failure (i'm in hurry right now can't check).
      But what comes in my mind is you can subclass QNetworkAccessManager and reimplement
      "createRequest()":http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html#createRequest and return a new QNetworkReply object. And write the contents to it of the "orginal request". If the original request fails, try it again ,... on success write all the data to the custom created QNetworkReply.

      Because i think you can't override QtWebkit's error handling on a failed request.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brcontainer
        wrote on 28 Jul 2013, 22:58 last edited by
        #3

        I did this:
        @QNetworkReply * myNAM::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData){
        if(op==PostOperation) {
        qDebug() << "isPost";
        QNetworkAccessManager *n = new QNetworkAccessManager();
        QFile delta("teste.txt");
        if(delta.open(QIODevice::WriteOnly)){
        delta.write(outgoingData->readAll());
        delta.close();
        }
        QNetworkReply *p = n->post(request,outgoingData);
        //qDebug() << p->url();
        //qDebug() << "newRequest";
        p->waitForReadyRead(8000);
        qDebug() << "readyRequest";
        if(p->isReadable()){
        qDebug() << "readyRequest is ready";
        return QNetworkAccessManager::createRequest(op, p->request(), outgoingData);
        }
        p->abort();
        }
        return QNetworkAccessManager::createRequest(op, request, outgoingData);
        }@

        But I can not get the POST data to arrive at the requested page.

        There comes a post empty (eg the response of PHP):
        code:
        @<?php
        print_r($_POST);
        ?>@

        Response (output), POST returned empty.:
        @Array();@

        Please help me make this code work!

        QT project: https://github.com/brcontainer/qt-helper

        1 Reply Last reply
        0
        • B Offline
          B Offline
          brcontainer
          wrote on 29 Jul 2013, 02:42 last edited by
          #4

          Solution: http://stackoverflow.com/a/17915208/1518921

          QT project: https://github.com/brcontainer/qt-helper

          1 Reply Last reply
          0

          1/4

          23 Jul 2013, 13:48

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved