Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-78934

QNetworkAccessManager denies to use user prefered network configuration

    XMLWordPrintable

Details

    • Linux/X11

    Description

      Hello there!

      It looks like a bug to me , but maybe I'm wrong and its indeed a wanted functionallity. 

      So in my case I try to set a specific network configuration named "wlan0"(other then the   QNetworkConfiguration::defaultConfiguration named "eth0") to a QNAM wich then should be used for all HTTP method calls like   QNetworkAccessManager::get, post, put etc

      QNetworkConfigurationManager config_manager;
      QList<QNetworkConfiguration> configs = config_manager.allConfigurations();
      for(const QNetworkConfiguration &config: configs) {
          if (config.name() == QStringLiteral("wlan0") &&
                  config.isValid() &&
                      config.state() == QNetworkConfiguration::Active) {
              m_pManager->setConfiguration(config);
              break;
          }
      }
      

      The "wlan0" configuration is valid and active, but the QNetworkConfiguration::defaultConfiguration will be still used by QNAM.

      I debugged the qt sources and found this piece of code (Qt/5.12.3/Src/qtbase/src/network/access/qnetworkaccessmanager.cpp:1420), which looks like a bug to me:

      if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
              if (!d->networkConfiguration.identifier().isEmpty()) {
                  if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined)
                          && d->networkConfiguration != d->networkConfigurationManager.defaultConfiguration())
                      d->createSession(d->networkConfigurationManager.defaultConfiguration());
                  else
                      d->createSession(d->networkConfiguration);
              } 
              ....
          } 
      

      When I do read the code right, it should be exactly the opposite :

      if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
              if (!d->networkConfiguration.identifier().isEmpty()) {
                  if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined)
                          && d->networkConfiguration != d->networkConfigurationManager.defaultConfiguration())
                      d->createSession(d->networkConfiguration);
                  else
                      d->createSession(d->networkConfigurationManager.defaultConfiguration());
              } 
              ....
          } 
      

      Attachments

        Activity

          People

            cnn Qt Core & Network
            maxwalter79 Maximilian Walter
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: