Type conversion and networkAccessManager->networkAccessible() problems in QT6.6
-
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 allowedAlso, 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' -
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 allowedAlso, 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'@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 allowedQComboBox::currentIndexChanged()
(notcurrentTextChanged()
) takes anint index
as its parameter. I don't understand how you can try to cast that to a function which takes aconst 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){ /* ... */ });
-
@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 allowedQComboBox::currentIndexChanged()
(notcurrentTextChanged()
) takes anint index
as its parameter. I don't understand how you can try to cast that to a function which takes aconst 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){ /* ... */ });
-
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.