Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Type conversion and networkAccessManager->networkAccessible() problems in QT6.6

Type conversion and networkAccessManager->networkAccessible() problems in QT6.6

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 313 Views
  • 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.
  • A Offline
    A Offline
    agha
    wrote on last edited by agha
    #1

    Hello friends, I have a type conversion problem in QT6.6. Although the function below works in older versions of QT, I get an error in QT6.6. The error is stated below.
    the code:
    void MainWindow::connectSerialPortComboBox() {

    connect(ui->serialPortComboBox, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
            picDriver, &QtPicDriver::setSerialPort);
    connect(ui->serialPortComboBox, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
            this, &MainWindow::saveSerialPortPref);
    

    }
    and Errors:
    error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed
    error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed

    Also, how can I recode the networkAccessManager->networkAccessible() operation in QT6.6?
    Thank you in advance for your help.

    void GitHubUpdateChecker::performCheck()
    {
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);

    if(softFailures >= maxTries) {
    	emit checkFailed();
    	checkInProgress = false;
    	return;
    }
    
    if(networkAccessManager->networkAccessible())
        networkAccessManager->get(QNetworkRequest(url));
    else {
        emit checkFailed();
        checkInProgress = false;
        return;
    }
    

    }
    the Error:

    error: no member named 'networkAccessible' in 'QNetworkAccessManager'
    error: no member named 'networkAccessible' in 'QNetworkAccessManager'

    JonBJ 1 Reply Last reply
    0
    • A agha

      Hello friends, I have a type conversion problem in QT6.6. Although the function below works in older versions of QT, I get an error in QT6.6. The error is stated below.
      the code:
      void MainWindow::connectSerialPortComboBox() {

      connect(ui->serialPortComboBox, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
              picDriver, &QtPicDriver::setSerialPort);
      connect(ui->serialPortComboBox, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
              this, &MainWindow::saveSerialPortPref);
      

      }
      and Errors:
      error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed
      error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed

      Also, how can I recode the networkAccessManager->networkAccessible() operation in QT6.6?
      Thank you in advance for your help.

      void GitHubUpdateChecker::performCheck()
      {
      QNetworkAccessManager *manager = new QNetworkAccessManager(this);

      if(softFailures >= maxTries) {
      	emit checkFailed();
      	checkInProgress = false;
      	return;
      }
      
      if(networkAccessManager->networkAccessible())
          networkAccessManager->get(QNetworkRequest(url));
      else {
          emit checkFailed();
          checkInProgress = false;
          return;
      }
      

      }
      the Error:

      error: no member named 'networkAccessible' in 'QNetworkAccessManager'
      error: no member named 'networkAccessible' in 'QNetworkAccessManager'

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @agha said in Type conversion and networkAccessManager->networkAccessible() problems in QT6.6:

      and Errors:
      error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed
      error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed

      QComboBox::currentIndexChanged() (not currentTextChanged()) takes an int index as its parameter. I don't understand how you can try to cast that to a function which takes a const QString& instead, which is what the error message says, and I don't know how that got through in any version of Qt --- ah, see below.

      I tried it in Qt5 and got:

      warning: ‘void QComboBox::currentIndexChanged(const QString&)’ is deprecated: Use currentIndexChanged(int) instead, and get the text using itemText(index) [-Wdeprecated-declarations]

      178 | connect(combo, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),

      So QComboBox::currentIndexChanged(const QString&) must have been finally removed in Qt6.

      And btw, even at Qt5 your code was not a good way to specify the choice of overloaded method if there are multiple possibilities. For that and if you come across this again at Qt6, as per https://doc.qt.io/archives/qt-5.14/qcombobox.html#currentIndexChanged-1 use QOverload<>::of():

      Note: Signal currentIndexChanged is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

      connect(comboBox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
          [=](const QString &text){ /* ... */ });
      
      A 1 Reply Last reply
      2
      • JonBJ JonB

        @agha said in Type conversion and networkAccessManager->networkAccessible() problems in QT6.6:

        and Errors:
        error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed
        error: static_cast from 'void (QComboBox::)(int)' to 'void (QComboBox::)(const QString &)' is not allowed

        QComboBox::currentIndexChanged() (not currentTextChanged()) takes an int index as its parameter. I don't understand how you can try to cast that to a function which takes a const QString& instead, which is what the error message says, and I don't know how that got through in any version of Qt --- ah, see below.

        I tried it in Qt5 and got:

        warning: ‘void QComboBox::currentIndexChanged(const QString&)’ is deprecated: Use currentIndexChanged(int) instead, and get the text using itemText(index) [-Wdeprecated-declarations]

        178 | connect(combo, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),

        So QComboBox::currentIndexChanged(const QString&) must have been finally removed in Qt6.

        And btw, even at Qt5 your code was not a good way to specify the choice of overloaded method if there are multiple possibilities. For that and if you come across this again at Qt6, as per https://doc.qt.io/archives/qt-5.14/qcombobox.html#currentIndexChanged-1 use QOverload<>::of():

        Note: Signal currentIndexChanged is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

        connect(comboBox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
            [=](const QString &text){ /* ... */ });
        
        A Offline
        A Offline
        agha
        wrote on last edited by
        #3

        @JonB
        Thank you for your answer. I'm a newbie to QT, so I need some more help.

        JonBJ 1 Reply Last reply
        0
        • A agha

          @JonB
          Thank you for your answer. I'm a newbie to QT, so I need some more help.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @agha

          error: no member named 'networkAccessible' in 'QNetworkAccessManager'

          https://doc.qt.io/qt-6/network-changes-qt6.html#bearer-management-is-removed

          QNetworkInformation::reachability(), introduced in Qt 6.1, replaces the QNetworkAccessManager::networkAccessible() function, while adding more detailed information about the reachability of the network. See its documentation for more details.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved