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. How to : detect network proxies using Qt
Servers for Qt installer are currently down

How to : detect network proxies using Qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 11.1k 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.
  • A Offline
    A Offline
    arnabkum
    wrote on last edited by
    #1

    My goal is to find all the proxy servers available on a network, using Qt. Another option might be to find the system proxy settings using Qt. However this might be more difficult to do in a clean way, I know that firefox just accesses the registry files when it needs them.

    Anyway, here is the code I have so far:
    @
    #include <QtGui/QApplication>
    #include <QtNetwork>

    int main(int argc, char *argv[])
    {
    QNetworkProxyQuery npq(QUrl("http://www.google.com"));
    QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);

    foreach (QNetworkProxy p, listOfProxies) {
        qDebug() << "hostname" << p.hostName();
    }
    

    } @

    Unfortunately, it only shows one proxy with no hostname, which I suspect is a "no proxy". This seems the most likely as p.type() returns 2

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shanek
      wrote on last edited by
      #2

      You can use QNetworkProxyFactory::setUseSystemConfiguration(true) to have the system settings used everywhere.

      Otherwise the code you have posted looks correct

      You haven't said which platform you're using.
      For windows and mac, the system proxy uses the system APIs and should be working well for most setups. (be aware that WPAD, aka "automatically detect proxy" is slow on windows)

      On linux, the http_proxy environment variable should be used.
      More complex setups using PAC files etc are not currently supported.
      (one possibility is to use libproxy)

      Above information is correct for 4.8 and 5.0 Qt versions

      1 Reply Last reply
      0
      • A Offline
        A Offline
        arnabkum
        wrote on last edited by
        #3

        I'm trying to create a cross-platform solution. Speed does not matter much for me, since this would be executed once on startup and once only.

        I guess I'm going to give this a go when on the job next time. But in the meantime, a follow up comment/question : is this better/worse than accessing the registry on windows? :o

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shanek
          wrote on last edited by
          #4

          It's the same.
          In fact Qt's implementation does access the registry.
          If the registry says to use a PAC file or WPAD, then windows API is used to do that.
          If you have a static configuration, then it is just returned directly.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            arnabkum
            wrote on last edited by
            #5

            Alright thanks again! =)

            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