Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Migrate old code from WebKit to WebEngine (QT6.5.2)
Forum Updated to NodeBB v4.3 + New Features

Migrate old code from WebKit to WebEngine (QT6.5.2)

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 2 Posters 327 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
    Zabarne
    wrote on last edited by
    #1

    Hi guys,

    Newbie here. I need some help to migrate this piece of WebKit code:

    mutateURL(const QUrl &oldURL)
    {
            QByteArray ba;
            ba.append(oldURL.toString().toStdString().c_str());
    
            QString newURL;
            newURL.append("http://192.168.1.21/check/");
            newURL.append(ba);
            return QUrl::fromUserInput(newURL);
    }
    
    createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
    {
    QUrl url= mutateURL(request.url());
    QNetworkRequest newReq = request;
    newReq.setUrl(url);
    QNetworkReply* mirroredRep = QNetworkAccessManager::createRequest(op, newReq, outgoingData);
    [...]
    

    What this code does is pretty simple: it intercepts all HTTP requests, create a new destination URL (by prepending "http://192.168.1.21/check/") to it and send the new request.

    As you can see, there's no "HTTP redirect involved". I would like to mimic this logic using WebEngine (QT6.5.2).

    Help appreciated.
    Many thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      From a quick look at the documentation, it seems that QWebEngineUrlRequestInterceptor is what you are looking for.

      On an unrelated note, why are you doing all these conversions through QByteArray since you want to concatenate two strings ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Z 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        From a quick look at the documentation, it seems that QWebEngineUrlRequestInterceptor is what you are looking for.

        On an unrelated note, why are you doing all these conversions through QByteArray since you want to concatenate two strings ?

        Z Offline
        Z Offline
        Zabarne
        wrote on last edited by
        #3

        Hi @SGaist

        Thanks.

        QWebEngineUrlRequestInterceptor is limited and only allows you to modify the HTTP request headers and/or perform an HTTP REDIRECT which I'd like to avoid here.

        The old code doesn't perform any REDIRECT.

        QByteArray since you want to concatenate two strings

        Indeed. As stated in the title, this is an old code :-)

        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