I have an application which runs a tool that requires network connection. Now my aim is to check whether the user has a network connection, if he don\'t have one, i can stra
this code will help you.
#include
#include
bool isConnectedToNetwork()
{
QList ifaces = QNetworkInterface::allInterfaces();
bool result = false;
for (int i = 0; i < ifaces.count(); i++)
{
QNetworkInterface iface = ifaces.at(i);
if ( iface.flags().testFlag(QNetworkInterface::IsUp)
&& !iface.flags().testFlag(QNetworkInterface::IsLoopBack) )
{
#ifdef DEBUG
// details of connection
qDebug() << "name:" << iface.name() << endl
<< "ip addresses:" << endl
<< "mac:" << iface.hardwareAddress() << endl;
#endif
// this loop is important
for (int j=0; j