Results 1 to 3 of 3

Thread: Correct usage of QNetworkProxy ?

  1. #1
    Join Date
    Jul 2015
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Correct usage of QNetworkProxy ?

    Hello,

    there is a proxy active and when I want to surf the web, I need to set up proxy settings on my computer, like:
    IP 123.234.0.1
    Port 12345
    User: ralfi
    Password: xxx

    When I run other programs (for instance JOSM), I just enter IP and port. JOSM then asks me my credentials, if necessary.

    In my own application, I also coded a proxy configuration:

    Qt Code:
    1. QNetworkProxy * proxy = new QNetworkProxy();
    2. //proxy->setType(QNetworkProxy::HttpProxy);
    3. proxy->setHostName(config.value("url").toString()); // "http://123.0.0.1"
    4. proxy->setPort(config.value("port").toUInt()); // 12345
    5.  
    6. // Credentials required ?
    7. if (config.value("authRequired").toBool()) {
    8. proxy->setUser(config.value("user").toString()); // "testUsr"
    9. proxy->setPassword(config.value("password").toString()); // "test123"
    10. }
    To copy to clipboard, switch view to plain text mode 
    As you can see, when I do not have any credentials, no user / password forwarded to the QNetworkProxy. Host and port only.

    1. When I do not enter credentials, as above, is there a possibility in QNetworkProxy , to popup a dialog on demand and to ask for credentials ?

    2. I set
    Qt Code:
    1. QNetworkProxy::setApplicationProxy(*proxy);
    To copy to clipboard, switch view to plain text mode 
    , but that has no effect. I still get a "Couldn't connect to server". What am I missing?

    Thanks in advance. Regards Ralf

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Correct usage of QNetworkProxy ?

    Quote Originally Posted by ralfwickum View Post
    1. When I do not enter credentials, as above, is there a possibility in QNetworkProxy , to popup a dialog on demand and to ask for credentials ?
    There is no built-in interactive GUI to do that in Qt network classes, if that is what you are looking for. You need to write your own dialog.

    If you send requests through QNetworkAccessManager, connect to the proxyAuthenticationRequired() signal; it emitted when the proxy needs authentication. You can open your blocking dialog in the slot (typically by calling QDialog::exec()).

    If you had rather set up the proxy before any request is made, just modify your code to show the dialog when config.value("authRequired").toBool() is false.

    Quote Originally Posted by ralfwickum View Post
    2. I set
    Qt Code:
    1. QNetworkProxy::setApplicationProxy(*proxy);
    To copy to clipboard, switch view to plain text mode 
    , but that has no effect. I still get a "Couldn't connect to server". What am I missing?
    It seems to be that your QNetworkProxy has no type. Why did you comment out line 2 in your code snippet?

  3. #3
    Join Date
    Jul 2015
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Correct usage of QNetworkProxy ?

    Quote Originally Posted by yeye_olive View Post
    There is no built-in interactive GUI to do that in Qt network classes, if that is what you are looking for.
    Ok, thanks for that.

    Quote Originally Posted by yeye_olive View Post
    It seems to be that your QNetworkProxy has no type. Why did you comment out line 2 in your code snippet?
    It was just for testing purposes. It had no effects anyway, since my proxy was not working at all.

Similar Threads

  1. Correct usage of setWindowFlags()?
    By 33333 in forum Newbie
    Replies: 1
    Last Post: 2nd July 2012, 07:08
  2. 100% correct usage of QSharedData
    By coder2012 in forum Qt Programming
    Replies: 4
    Last Post: 21st May 2012, 01:14
  3. Correct usage of QThread
    By Patrik in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2012, 15:54
  4. Replies: 1
    Last Post: 9th May 2011, 13:16
  5. QNetworkProxy
    By becrux in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2008, 21:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.