Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Usage of specific QNetworkConfiguration on android

    Mobile and Embedded
    1
    1
    113
    Loading More Posts
    • 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.
    • J
      JohnAmadis last edited by

      Hi,

      I work on android application that needs to connect to a server in a WLAN. The problem is that this WLAN does not have internet access, so on some devices it is not set as default network configuration in QNetworkAccessManager::activeConfiguration()

      I found the required config in QNetworkConfigurationManager::allConfigurations() but I dont have an idea how can I force QTcpSocket to use this instead of the default one. I tried to do this for example in this way:
      (Sorry for the ugly code - it is just for test as I am currently looking for some solution)

      QNetworkConfigurationManager configurationsManager;
                  auto configurations = configurationsManager.allConfigurations();
                  for ( auto config : configurations )
                  {
                      auto b = config.bearerType();
                      if ( b == QNetworkConfiguration::BearerWLAN )
                      {
                          auto networkSession = new QNetworkSession( currentConfiguration );
                          networkSession->open();
                          networkSession->waitForOpened();
                          QNetworkConfiguration config = networkSession->configuration();
                          QString id;
                          if (config.type() == QNetworkConfiguration::UserChoice)
                              id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
                          else
                              id = config.identifier();
      
                          QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
                          settings.beginGroup(QLatin1String("QtNetwork"));
                          settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
                          settings.endGroup();
                          break;
                      }
                  }
      

      But it did not help at all... Do you know how can I change the active configuration or pass it to the QTcpSocket to force it to use this interface?

      Best Regards,
      Patryk

      1 Reply Last reply Reply Quote 0
      • First post
        Last post