Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Setting User And Password For Qt WebView & WebEngine Diectly
Forum Updated to NodeBB v4.3 + New Features

Setting User And Password For Qt WebView & WebEngine Diectly

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 2.7k Views 2 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.
  • Pablo J. RoginaP Offline
    Pablo J. RoginaP Offline
    Pablo J. Rogina
    wrote on last edited by
    #5

    @shahriar25 maybe the trick here is that QWebPage within your QWebView is using its own QNetworkAccessManager, so perhaps by doing:

    myWebView->page()->setNetworkAccessManager(yourQNAM)
    

    will cause the webview to use your QNAM with your proxy settings.

    Upvote the answer(s) that helped you solve the issue
    Use "Topic Tools" button to mark your post as Solved
    Add screenshots via postimage.org
    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shahriar25
      wrote on last edited by
      #6

      @Pablo-J-Rogina
      Well see that is the problem. I'm working with qml and using webview in it

      1 Reply Last reply
      0
      • Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #7

        @shahriar25 are you saying you're using this QML WebView component? If so, on one side you should have stated your issue better :-) and you may need to work with the underlying QNetworkAccessManager of QML, see this post as a guideline.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • S Offline
          S Offline
          shahriar25
          wrote on last edited by shahriar25
          #8

          @Pablo-J-Rogina
          Hi. I'm sorry for late reply
          I'm sorry if I left out using qml. It wasn't intentional
          I tried this:

          class QmlNAMFactory : public QQmlNetworkAccessManagerFactory
          {
          virtual QNetworkAccessManager *create(QObject *parent)
          {
          QNetworkAccessManager *nam = new QNetworkAccessManager(parent);
          QNetworkProxy proxy;

          	proxy.setType(QNetworkProxy::HttpProxy);
                      // proxy info here
          
          	nam->setProxy(proxy);
          	return nam;
          }
          

          };

          QQmlApplicationEngine engine;
          engine.setNetworkAccessManagerFactory(new QmlNAMFactory);

          but this has no effect on webview. It doesn't change a thing
          I'm sorry the function was returning nullptr I edited it. I did that just to text the effect

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shahriar25
            wrote on last edited by
            #9

            Isn't there anything that I can do?

            1 Reply Last reply
            0
            • i.n.g.o.I Offline
              i.n.g.o.I Offline
              i.n.g.o.
              wrote on last edited by
              #10

              Hi.

              Did you solve the problem?

              I am hitting the same problem, i need to set a header to every QML WebView request.

              Setting the network access manager on QQmlApplicationEngine does not call MyNetworkAccessManagerFactory::create.
              Seems WebView is not using QNetworkAccessManager at all.

              Is this possible at all?

              thanks for hints.

              A Ronel_qtmasterR 2 Replies Last reply
              0
              • i.n.g.o.I i.n.g.o.

                Hi.

                Did you solve the problem?

                I am hitting the same problem, i need to set a header to every QML WebView request.

                Setting the network access manager on QQmlApplicationEngine does not call MyNetworkAccessManagerFactory::create.
                Seems WebView is not using QNetworkAccessManager at all.

                Is this possible at all?

                thanks for hints.

                A Offline
                A Offline
                Anton Beresnev
                wrote on last edited by
                #11

                @i-n-g-o Hi.Do you solve problem?

                1 Reply Last reply
                0
                • i.n.g.o.I i.n.g.o.

                  Hi.

                  Did you solve the problem?

                  I am hitting the same problem, i need to set a header to every QML WebView request.

                  Setting the network access manager on QQmlApplicationEngine does not call MyNetworkAccessManagerFactory::create.
                  Seems WebView is not using QNetworkAccessManager at all.

                  Is this possible at all?

                  thanks for hints.

                  Ronel_qtmasterR Offline
                  Ronel_qtmasterR Offline
                  Ronel_qtmaster
                  wrote on last edited by
                  #12

                  @i-n-g-o it does

                  1 Reply Last reply
                  0
                  • Ronel_qtmasterR Offline
                    Ronel_qtmasterR Offline
                    Ronel_qtmaster
                    wrote on last edited by
                    #13

                    The first thing to do is to create a network access Manager factory class

                    NetworkAccessManagerFactory.cpp

                    #include "networkaccessmanagerfactory.h"

                    QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent)
                    {

                    QNetworkAccessManager *manager = new QNetworkAccessManager(parent);
                    return manager;
                    }

                    NetworkAccessManagerFactory.h

                    #ifndef NETWORKACCESSMANAGERFACTORY_H
                    #define NETWORKACCESSMANAGERFACTORY_H
                    #include "customnetworkaccessmanager.h"
                    #include <QNetworkAccessManager>
                    #include <QNetworkProxy>
                    #include <QQmlEngine>
                    #include <QQmlNetworkAccessManagerFactory>
                    #include <QtNetwork>

                    class NetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
                    {

                    public:
                    QNetworkAccessManager *create(QObject *parent) override;

                    private:

                    };

                    #endif // NETWORKACCESSMANAGERFACTORY_H

                    Then finally add to qml side by writing this in the main.cpp

                    NetworkAccessManagerFactory customNam;

                    QQmlApplicationEngine engine;
                    engine.setNetworkAccessManagerFactory(&customNam);
                    
                    1 Reply Last reply
                    0
                    • Ronel_qtmasterR Offline
                      Ronel_qtmasterR Offline
                      Ronel_qtmaster
                      wrote on last edited by
                      #14

                      you can also check this as well
                      https://code.qt.io/cgit/qt/qtdeclarative.git/tree/examples/qml/networkaccessmanagerfactory?h=5.15

                      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