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



  • 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



  • 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;
    

    @



  • 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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.