Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
How to get the file size in Qt??

i have used GetFileSize() but its not working.. pls help me..
Posted
Updated 9-Jul-13 22:30pm
v2

You can simply use QFile::size() function to get size of file.
 
Share this answer
 
Comments
Gokulnath007 8-Mar-11 5:13am    
QFile::size() .. function returns 0.but the file size is 444kb.
Hi,

there is a thread about this topic in the Qt Project forum.
A possible error in your case may be that QFile::size() returns '0' if the file can't be opened for read, even if the file size is greater than '0'. Therefore you need to check whether the file can be opened for a read operation (And don't forget to close it afterwards!):

C++
int size = 0;
QFile myFile("C:\\file.txt");
if (myFile.open(QIODevice::ReadOnly)){
    size = myFile.size();  //when file does open.
    myFile.close();
} 


Source: Qt Project Forums[^]


cheers
mabertschi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900