Results 1 to 5 of 5

Thread: use of QNetworkAccessManager::networkAccessible

  1. #1
    Join Date
    Dec 2010
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default use of QNetworkAccessManager::networkAccessible

    Has anybody successfully used QNetworkAccessManager::networkAccessible ?
    if so can you please post how I can use it? When I try to use it, it just returns a -1.

    Thank you,
    sky.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: use of QNetworkAccessManager::networkAccessible

    Which means it can not determine the accessibility of the network on the platform that you are running your application on.

  3. #3
    Join Date
    Dec 2010
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: use of QNetworkAccessManager::networkAccessible

    Thanks squidge. I should have poseted more details. Here they are:

    Windows 7 professional, Intel i5.
    my code looks like this:
    Qt Code:
    1. if (pNetwork->networkAccessible()!=QNetworkAccessManager::Accessible)
    2. {
    3. qCritical()<<"Network is not accessible." <<pNetwork->networkAccessible();
    4. while ((pNetwork->networkAccessible()!=QNetworkAccessManager::Accessible)) {}
    5. }
    To copy to clipboard, switch view to plain text mode 
    And my code is always getting stuck in the while loop. While I am able to access the internet on the same computer all the while. Please let me know if I am missing anything. Thank you.
    Last edited by sky; 4th January 2011 at 18:25. Reason: formating

  4. #4
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: use of QNetworkAccessManager::networkAccessible

    I know this is an old thread but I stumbled across it while looking for an answer to same the question and thought I would update the thread with an answer

    QNetworkAccessManager::networkAccessible is not explicitly set when the QNetworkAccessManager is created. It is only set after the network session is initialized. The session is initialized automatically when you make a network request or you can initialize it before hand with QNetworkAccessManager::setConfiguration() or the QNetworkConfigurationManager::NetworkSessionRequir ed flag is set.

    Adding the following snippet of code after the QNetworkAccessManager is created would do the trick

    Qt Code:
    1. QNetworkAccessManager* mNetworkAccessManager = new QNetworkAccessManager();
    2. QNetworkConfigurationManager manager;
    3. mNetworkAccessManager->setConfiguration(manager.defaultConfiguration());
    To copy to clipboard, switch view to plain text mode 

    now any subsequent calls to

    Qt Code:
    1. mNetworkAccessManager->networkAccessible();
    To copy to clipboard, switch view to plain text mode 

    will return properly (instead of constantly returning QNetworkAccessManager::UnknownAccessibility (-1) )

  5. The following user says thank you to Berryblue031 for this useful post:

    sky (14th June 2011)

  6. #5
    Join Date
    Aug 2011
    Posts
    44
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: use of QNetworkAccessManager::networkAccessible

    I'm not sure this is quite right.
    My app throws many successful network requests through single QNetworkAccessManager.
    Just tested for sure.
    networkAccessible() remains -1, no networkAccessibleChanged signal emitted.
    I saw such behavior on older Qt's and now see the same on 4.8.0b1. OS: Windows 7.

    I didn't try to set configuration explicitly as you pointed as alternative case.

    PS. I saw networkAccessible working in some way on Symbian^3 devices.

Similar Threads

  1. QNetworkAccessManager and phonon - can it be done?
    By serenti in forum Qt Programming
    Replies: 16
    Last Post: 2nd December 2011, 18:32
  2. QNetworkAccessManager and redirections
    By alexandernst in forum Qt Programming
    Replies: 33
    Last Post: 22nd September 2010, 19:05
  3. qnetworkaccessmanager problem!
    By novamaster in forum Qt Programming
    Replies: 6
    Last Post: 7th August 2010, 11:46
  4. QNetworkAccessManager and https. help!
    By valerino in forum Qt Programming
    Replies: 0
    Last Post: 22nd July 2010, 14:13
  5. How to Login using QNetworkAccessManager?
    By cydside in forum Newbie
    Replies: 1
    Last Post: 31st August 2009, 21:41

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.