Re: Check network connection
I'd suggest you to use
Code:
socket->connectToHost("hostName", portNumber);
if (socket->waitForConnected(1000))
qDebug("Connected!");
.
In this method, you can try connecting to a valid host to a period of time and if it succeeds then fine otherwise time out will occur. The value of trying time is in your hands.
Re: Check network connection
The best way is probably a ping request, which Qt doesn't seem to support, plus on some OSs it requires higher priviledges as it needs raw sockets.
Best Qt way is to try and connect to a host and see if it works.
Re: Check network connection
Quote:
Originally Posted by
fatjuicymole
The best way is probably a ping request, which Qt doesn't seem to support,
Then why you are mentioning it here.;)
Re: Check network connection
As it's still the best, even if Qt doesn't support it. Plus, maybe someone will create a class to do and submit it to Nokia if they think it'll be useful.
Typically, if you talk about something that isn't possible regularly enough, it becomes a wanted feature, and gets implemented :)
If we only ever talk about things which are possible, then the toolkit will never get extended or enhanced, as people will think it supports everything you could ever want.
Re: Check network connection
Quote:
Originally Posted by
fatjuicymole
As it's still the best, even if Qt doesn't support it. Plus, maybe someone will create a class to do and submit it to Nokia if they think it'll be useful.
On most platforms you wouldn't be able to send an IMCP packet without superuser privileges so it would be hard to call that a portable solution which means it wouldn't go to Qt anyway. And on the remaining platforms it's just a few lines of code to implement it natively. Besides, there is always QProcess and the 'ping' command available on most platforms.
Re: Check network connection
If 'ping' and QProcess is available on most platforms, wouldn't you call such thing a solution which could be portable? There could be a class which does it natively on platforms which support it, and via QProcess for platforms that don't.
Re: Check network connection
Quote:
Originally Posted by
fatjuicymole
If 'ping' and QProcess is available on most platforms, wouldn't you call such thing a solution which could be portable?
Not really. Qt doesn't do such things like using QProcess to access some other executable to do some job, then parse all possible kinds of output and return the result to the user. Besides, at least on some Linux distros ping requires you to have superuser access rights as well.
I would be more interested in seeing proper support for serial devices in Qt rather than a wrapper around ping. Which is completely unreliable as a method to check if you have a working network connection, by the way.
Re: Check network connection
Hello guys.
How can i specify the connection type?
I want to check the VPN connections only. how can i do that in Qt? i have already written a code to check for Network Connectivity now all i need is to specify it to a VPN connection only.
Here is my code so far"
Code:
bool MainWindow::CheckNetworkConnectivity()
{
for(int i = 0; i < interfaces.count();i++)
{
if(interface.IsUp && !interface.IsLoopBack)
{
ui
->lstLog
->addItem
(interface.
name()+QDateTime::currentDateTime().
toString("h:m:s ap"));
ui->chkConStatus->setChecked(true);
}
else{
ui->chkConStatus->setChecked(false);
}
}
return ui->chkConStatus->checkState();
}
Regards in advance :)
Hossein