Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [solved] Qt 5.4 - Proxy settings for QtWebEngine

[solved] Qt 5.4 - Proxy settings for QtWebEngine

Scheduled Pinned Locked Moved Mobile and Embedded
14 Posts 4 Posters 12.4k Views
  • 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.
  • P Offline
    P Offline
    pcushman
    wrote on 17 Dec 2014, 16:19 last edited by
    #4

    Can you share how you are setting up the proxy settings (host and port) for the QtWebEngine? My QWebEngineView does not honor the proxy settings made via the QNetworkProxy::setApplicationProxy(proxy) call.
    thanks
    Paul

    P 1 Reply Last reply 21 Apr 2015, 07:39
    0
    • P Offline
      P Offline
      pcushman
      wrote on 17 Dec 2014, 16:19 last edited by
      #5

      Can you share how you are setting up the proxy settings (host and port) for the QtWebEngine? My QWebEngineView does not honor the proxy settings made via the QNetworkProxy::setApplicationProxy(proxy) call.
      thanks
      Paul

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nando76
        wrote on 17 Dec 2014, 17:45 last edited by
        #6

        Hi Paul.
        i do it like this:

        In my class i have a member of:
        @
        QNetworkProxy m_networkProxy;
        @

        in constructor of my class i create the QNetworkAccessManager:
        @
        m_networkAccessManager = new QNetworkAccessManager;
        @

        and the after loading proxy host, port,username and password i set it like this:
        @
        if (m_proxyEnabled) {
        m_networkProxy.setType(QNetworkProxy::HttpProxy);
        m_networkProxy.setHostName(m_ProxyHost);
        m_networkProxy.setPort(m_ProxyPort);
        m_networkProxy.setUser(m_ProxyUsername);
        m_networkProxy.setPassword(m_ProxyPassword);
        } else {
        m_networkProxy.setType(QNetworkProxy::NoProxy);
        }

        // Apply the proxy to the QNetworkAccessManager
        QNetworkProxy::setApplicationProxy(m_networkProxy);
        m_pNetworkAccessManager->setProxy(m_networkProxy);
        

        @

        Hope that helps ;-)

        Greetings
        Nando

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nando76
          wrote on 17 Dec 2014, 17:45 last edited by
          #7

          Hi Paul.
          i do it like this:

          In my class i have a member of:
          @
          QNetworkProxy m_networkProxy;
          @

          in constructor of my class i create the QNetworkAccessManager:
          @
          m_networkAccessManager = new QNetworkAccessManager;
          @

          and the after loading proxy host, port,username and password i set it like this:
          @
          if (m_proxyEnabled) {
          m_networkProxy.setType(QNetworkProxy::HttpProxy);
          m_networkProxy.setHostName(m_ProxyHost);
          m_networkProxy.setPort(m_ProxyPort);
          m_networkProxy.setUser(m_ProxyUsername);
          m_networkProxy.setPassword(m_ProxyPassword);
          } else {
          m_networkProxy.setType(QNetworkProxy::NoProxy);
          }

          // Apply the proxy to the QNetworkAccessManager
          QNetworkProxy::setApplicationProxy(m_networkProxy);
          m_pNetworkAccessManager->setProxy(m_networkProxy);
          

          @

          Hope that helps ;-)

          Greetings
          Nando

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pcushman
            wrote on 17 Dec 2014, 19:46 last edited by
            #8

            Hi Nando
            I tried your suggestions but it did not work.
            I have the following class and associated methods:

            @
            class LoginWebEngineView : public QWebEngineView
            {
            Q_OBJECT

            public:
            explicit LoginWebEngineView(QWidget *parent = 0, QSettings *settings = 0);
            ~LoginWebEngineView();
            void setProxy();

            private:
            QSettings* m_pSettings;
            QNetworkProxy m_networkProxy;
            QNetworkAccessManager *m_pNetworkAccessManager;
            };

            LoginWebEngineView::LoginWebEngineView(QWidget *parent, QSettings *settings) :
            QWebEngineView(parent)
            {
            m_pSettings = settings;
            m_pNetworkAccessManager = new QNetworkAccessManager;

            this->setParent(parent);
            setProxy();
            

            }

            void
            LoginWebEngineView::setProxy() {
            if (m_pSettings->value("proxy_enabled", false).toBool()) {
            QString host = m_pSettings->value("proxy_host", "").toString();
            quint16 port = m_pSettings->value("proxy_port", 0).toUInt();
            QString user = m_pSettings->value("proxy_user", "").toString();
            QString password = m_pSettings->value("proxy_pass", "").toString();

                m_networkProxy.setType(QNetworkProxy::HttpProxy);
                m_networkProxy.setHostName(host);
                m_networkProxy.setPort(port);
                m_networkProxy.setUser(user);
                m_networkProxy.setPassword(password);
            } else {
                m_networkProxy.setType(QNetworkProxy::NoProxy);
            }
            
            // Apply the proxy to the QNetworkAccessManager
            QNetworkProxy::setApplicationProxy(m_networkProxy);
            m_pNetworkAccessManager->setProxy(m_networkProxy);
            

            }

            @

            If you see anything obvious, please let me know.
            thanks
            Paul

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pcushman
              wrote on 17 Dec 2014, 19:46 last edited by
              #9

              Hi Nando
              I tried your suggestions but it did not work.
              I have the following class and associated methods:

              @
              class LoginWebEngineView : public QWebEngineView
              {
              Q_OBJECT

              public:
              explicit LoginWebEngineView(QWidget *parent = 0, QSettings *settings = 0);
              ~LoginWebEngineView();
              void setProxy();

              private:
              QSettings* m_pSettings;
              QNetworkProxy m_networkProxy;
              QNetworkAccessManager *m_pNetworkAccessManager;
              };

              LoginWebEngineView::LoginWebEngineView(QWidget *parent, QSettings *settings) :
              QWebEngineView(parent)
              {
              m_pSettings = settings;
              m_pNetworkAccessManager = new QNetworkAccessManager;

              this->setParent(parent);
              setProxy();
              

              }

              void
              LoginWebEngineView::setProxy() {
              if (m_pSettings->value("proxy_enabled", false).toBool()) {
              QString host = m_pSettings->value("proxy_host", "").toString();
              quint16 port = m_pSettings->value("proxy_port", 0).toUInt();
              QString user = m_pSettings->value("proxy_user", "").toString();
              QString password = m_pSettings->value("proxy_pass", "").toString();

                  m_networkProxy.setType(QNetworkProxy::HttpProxy);
                  m_networkProxy.setHostName(host);
                  m_networkProxy.setPort(port);
                  m_networkProxy.setUser(user);
                  m_networkProxy.setPassword(password);
              } else {
                  m_networkProxy.setType(QNetworkProxy::NoProxy);
              }
              
              // Apply the proxy to the QNetworkAccessManager
              QNetworkProxy::setApplicationProxy(m_networkProxy);
              m_pNetworkAccessManager->setProxy(m_networkProxy);
              

              }

              @

              If you see anything obvious, please let me know.
              thanks
              Paul

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nando76
                wrote on 17 Dec 2014, 20:05 last edited by
                #10

                Hi,
                i see you have enhirted your class from QWebEngineView.
                Try to inherit your class just from QObject and add a member for the
                QWebEngineView which gets instantiated before the set proxy stuff:
                @
                QWebEngineView* m_webEngineView;
                @

                Maybe QWebEngine is looking for proxy settings while creation and there are no proxy stettings at construction time.

                Greetings
                Nando

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  nando76
                  wrote on 17 Dec 2014, 20:05 last edited by
                  #11

                  Hi,
                  i see you have enhirted your class from QWebEngineView.
                  Try to inherit your class just from QObject and add a member for the
                  QWebEngineView which gets instantiated before the set proxy stuff:
                  @
                  QWebEngineView* m_webEngineView;
                  @

                  Maybe QWebEngine is looking for proxy settings while creation and there are no proxy stettings at construction time.

                  Greetings
                  Nando

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pcushman
                    wrote on 17 Dec 2014, 21:12 last edited by
                    #12

                    That did not help. My dialog is created in QtCreator, is it possible that this could be part of the issue?
                    thanks
                    Paul

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pcushman
                      wrote on 17 Dec 2014, 21:12 last edited by
                      #13

                      That did not help. My dialog is created in QtCreator, is it possible that this could be part of the issue?
                      thanks
                      Paul

                      1 Reply Last reply
                      0
                      • P pcushman
                        17 Dec 2014, 16:19

                        Can you share how you are setting up the proxy settings (host and port) for the QtWebEngine? My QWebEngineView does not honor the proxy settings made via the QNetworkProxy::setApplicationProxy(proxy) call.
                        thanks
                        Paul

                        P Offline
                        P Offline
                        Peng
                        wrote on 21 Apr 2015, 07:39 last edited by
                        #14

                        @pcushman
                        Hi, have you solved your proxy problem now? Because I meet the same question as you.

                        Thanks,
                        Peng

                        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