[Moved] Http request in QtNetwork



  • Hi, I have a problem with a simple HTTP request.

    It works fine with some networks, even if I'm not connected it gets the signal and complete the petition without error.

    But with some others, even when the browser is working, the petition emit a error signal.

    @
    QNetworkAccessManager qn;
    reply = qn.get(QNetworkRequest(QUrl("http://www.google.es")));

    // All the signals connections
    connect(...);
    @

    I tried with this example code from nokia

    @
    // Set Internet Access Point
    QNetworkConfigurationManager manager;

    const bool canStartIAP = (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces);
    
    // Is there default access point, use it
    QNetworkConfiguration cfg = manager.defaultConfiguration();
    
    if (!cfg.isValid() || !canStartIAP) {
        // Available Access Points not found
        return;
    }
    
    // Open session
    m_session = new QNetworkSession(cfg);
    m_session->open();
    
    // Waits for session to be open and continues after that
    m_session->waitForOpened();
    qDebug() << m_session->state();
    

    @

    In the cases that it doesn't work it prints "1" that means QNetworkSession::NotAvailable.
    I don't know what I'm doing wrong.

    Thanks in advance.



  • Looks like question is about mobile platforms? Moved to Mobile category from Quick.

    P.S. 2Moderators: if further discussion will reveal that question is about not only mobile platforms feel free to move it to general.



  • It's fine I usually post there because I work creating Qt Quick application, so I didn't check if there was a more specific forum about that topic. Sorry!



  • So it is mobile-related question, right?



  • Ahh yes, its about mobilephone. I didn't say it sorry.

    Well I found a solution, I don't know if it's the best but at least something...

    I leave it here just in case someone ask the same:

    @QNetworkConfigurationManager manager;
    QList<QNetworkConfiguration> activeConfigs = manager.allConfigurations(QNetworkConfiguration::Active);
    if(activeConfigs.count()) qnam.setConfiguration(activeConfigs.at(0));
    else qnam.setConfiguration(manager.defaultConfiguration());
    @

    qnam is suppose to be the qNetworkAccessManager


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.