tags:

views:

64

answers:

2

Possible Duplicate:
How to determine how much free space on a drive in Qt?

How can I check disk fullness with C++ using Qt ? Thanks a lot

A: 

Apparently not. But I found this here:

#ifdef _WIN32
    #include <windows.h>
#else // linux stuff
    #include <sys/vfs.h>
    #include <sys/stat.h>
#endif // _WIN32

bool getFreeTotalSpace(const QString& sDirPath,double& fTotal, double& fFree)
{
#ifdef _WIN32

    QString sCurDir = QDir::current().absPath();
    QDir::setCurrent( sDirPath );

    ULARGE_INTEGER free,total;
    bool bRes = ::GetDiskFreeSpaceExA( 0 , &free , &total , NULL );
    if ( !bRes ) return false;

    QDir::setCurrent( sCurDir );

    fFree = static_cast<double>( static_cast<__int64>(free.QuadPart) ) / fKB;
    fTotal = static_cast<double>( static_cast<__int64>(total.QuadPart) ) / fKB;

#else //linux

    struct stat stst;
    struct statfs stfs;

    if ( ::stat(sDirPath.local8Bit(),&stst) == -1 ) return false;
    if ( ::statfs(sDirPath.local8Bit(),&stfs) == -1 ) return false;

    fFree = stfs.f_bavail * ( stst.st_blksize / fKB );
    fTotal = stfs.f_blocks * ( stst.st_blksize / fKB );

#endif // _WIN32

    return true;
}
sje397
Thans for your answer but I couldnt understand this, can you tell me about it. Thanks a lot
john
What is fKB value?
john
A: 

This is a duplicate of http://stackoverflow.com/questions/1732717/how-to-determine-how-much-free-space-on-a-drive-in-qt

flitzwald
This should just be a comment on the question but thanks for pointing it out.
Troubadour