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] How to get and change HTML from url before viewing in QWebView?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to get and change HTML from url before viewing in QWebView?

Scheduled Pinned Locked Moved Qt WebKit
5 Posts 3 Posters 6.8k 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.
  • Z Offline
    Z Offline
    zither
    wrote on last edited by
    #1

    Dear all friends,

    I would like to get and change HTML from internet url before viewing in QWebView.
    When I try to load newly change HTML to set in QWebView after loadFinish() signal. It's OK.

    But when I try to change contents of Facebook page, & try to insert newly change HTML, it's not work.
    When I write out change HTML to a file, It's OK, open that file in browser also OK.

    That's why? I would like to know..
    So, Is it possible to get HTML, change them & return to QWebView before settings original HTML to QWebView?

    Thanks

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jim_kaiser
      wrote on last edited by
      #2

      What's the difference from the "previous post":http://developer.qt.nokia.com/forums/viewthread/6742/#39382?

      To get html without QWebView. Do this:

      [ Edit: NOTE: QHttp is obsolete as pointed out by many others and shouldn't be used. Use the QNetworkManager instead. ]

      [Edit2:
      @
      // constructor
      m_networkManager = new QNetworkAccessManager(this);

      connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
      this, SLOT(slotReplyFinished(QNetworkReply*)));

      //get
      m_networkManager->get(QNetworkRequest(QUrl(queryUrlString)));

      //slotReplyFinished(QNetworkReply *response)
      {
      QByteArray result;

      if (response->error() == QNetworkReply::NoError)
      {
          result = response->readAll();
      }
      else
          QMessageBox::critical(this, tr("Error"), response->errorString());
      

      }
      @
      ]

      Obsolete method using QHttp.
      @
      // In constructor
      m_http_buffer = new QTemporaryFile();
      m_http_buffer->setAutoRemove(true);
      m_http_client = new QHttp(this);

      // Http call
      QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? Http::ConnectionModeHttps : QHttp::ConnectionModeHttp;
      m_http_client->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
      m_http_buffer->open();

      httpRequestId = m_http_client->get(url.path(),m_http_buffer);

      setCursor(QCursor(Qt::WaitCursor));

      connect(m_http_client, SIGNAL(requestFinished(int,bool)),
      this, SLOT(slotHttpRequestFinished(int,bool)));

      // slotHttpRequestFinished
      if (id==httpRequestId)
      {
      setLocked(false);
      setCursor(QCursor(Qt::ArrowCursor));

          if (!error)
          {
              m_http_buffer->seek(0);
      
              // read response here
              m_http_buffer->readAll());
              
              m_http_buffer->close();
      
              disconnect(m_http_client, 0, this, 0);
         }
      }
      

      @

      @
      In header:
      private slots:
      void slotHttpRequestFinished(int id, bool error);

      private:
         QHttp   *m_http_client;
         int     httpRequestId;
         QTemporaryFile  *m_http_buffer;
      

      @

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zither
        wrote on last edited by
        #3

        Dear friend,

        Thanks for your reply

        I want to change some data on HTML requested from internet.
        It's like Firefox plug-in which change some HTML & is shown in main browser to user.
        When I insert just some html text instead of change function, It's also work.

        But, my change function is also work, I tested with changed data to output file.
        That output file can be opened & show correctly in FF for my changes.

        I don't understand why my browser can't show these changes. It's just some Unicode character corrections. I recompile Qt lib for these unicode support.

        Thanks

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jim_kaiser
          wrote on last edited by
          #4

          Okay :) If solved.. could mark as solved in title?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kkrzewniak
            wrote on last edited by
            #5

            NOTE: Do not use QHttp this class is deprecated! Use QNetworkAccessManager instead!!

            Me, Grimlock, not "nice dino". ME BASH BRAINS!

            1 Reply Last reply
            0

            • Login

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