Re: File exists on server
Quote:
Originally Posted by
Chops211
Simple question:
Is there anyway to tell if a file exists on a server or network address such as //192.168.0.2/foo/bar.txt
I use QFile::exists( "\\192.168.0.2\foo\bar.txt" ) which works perfectly when connected to the server but say I was in an airport and not connected to the same network, the exists() function hangs and does not timeout.
Is there any way to detect if there is a connection to the server?
Thanks in advance
I believe this is what you are looking for.
http://www.qtcentre.org/threads/2542...ork-connection
Regards,
Re: File exists on server
Thank you. I tried this before and I wanted something much simpler that doesn't require using sockets. I want to leave as much as I can to the OS. I really would like a QFile::exists() function with a timeout. or QDir()
Re: File exists on server
I guess one of the easier things to do is use ifconfig or ipconfig and parse the results.
The correct way to do this is to use platform specific functions and this will require you to write some code.
There are only a few things you get for free: the sun going up, death and taxes.
So don't be lazy and start writing a little bit of code.
Re: File exists on server
To add up to what was posted You could either use QProcess with ping and check result or simply:
Code:
void MainWindow::someFunction(){
connect( sock, SIGNAL(hostFound()), this, SLOT( checkFile() ) );
sock->connectToHost( "192.168.0.2", 421 );
}
void MainWindow::checkFile()
{
qDebug
() <<
"File Exists?:" <<
QFile::exists( "\\192.168.0.2\foo\bar.txt" );
}
or beter use SIGNAL( stateChanged(QAbstractSocket::SocketState) )
Its add a few lines to Your code and is IMHO simple.
Re: File exists on server
Thanks everyone. Using ifconfig or ipconfig doesn't really make sense when I could just use sockets but thank you for the idea.