I have a task to get size of block devices, it must be cross-platform application (Linux/Windows) so I use Qt, can I get file size of block devices usin Qt standard classes such as QFile and QFileInfo? My sketch program doesn’t work correct:
#include <QtCore/QCoreApplication>
#include <iostream>
#include <QFileInfo>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFileInfo info("/dev/sda5");
if(info.isReadable())
std::cout<<"/dev/sda1 isReadable\n";
else
std::cout<<"Cant read /dev/sda5";
std::cout<<info.size()<<"\n";
return a.exec();
}
It shows “/dev/sda5 isReadable” and size equals zero, can you help me with this problem?
You have to use
statfson Linux andGetDiskFreeSpaceExon Windows. It does not seem that Qt was wrapping that function, but it’s rather short piece of code.Device nodes report size of zero via usual stat call. That’s a fact and you can’t do much about it. It’s not interesting anyway, because it’s quite a lot of unix-specific work to find out which device is mounted on some path.