How to find the network availability in Qt?
-
I don't think that there is any api for network availability in Qt. But i am not 100% sure.
Yes. You can find api for any particular platform. Such as there is an api available in windows for network availability.
-
I have tried this on windows and it works. Not tried on Linux. Will try.
@QNetworkConfigurationManager mgr;
QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active);
if (activeConfigs.count() > 0) {
Q_ASSERT(mgr.isOnline());
if (mgr.isOnline()){
qDebug() << "connected" <<endl;
}else{
qDebug() << "Inside not connected"<<endl;
}
}
if (!mgr.isOnline()){
Q_ASSERT(!mgr.isOnline());
qDebug() << "not connected" <<endl;
}@ -
Thanks for your reply.
I will try with qt build soon.
I tried with QNetworkConfigurationManager *mngr = new QNetworkConfigurationManager(this);
bool b = mngr->isOnline();
It's always return false with build of Qt installer.(in production on user machine)
When I build binary from qt creator, it's returning correct network status. May I know the reason for this?
Is there extra library required on user machine?
-
@
QNetworkConfigurationManager mgr;
QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active);@Did you query like the above ? It just requires network module. Nothing more.
-
Hi Dheerendra,
I tried with your code too with build. No luck.
It's always returning false even though network available.
If I build binary on my machine, it's returning correct network status.
Is there any other library dependency while compiling?
Thanks.
-
Hi,
IIRC, the bearer plugin