File size
-
@
QFile mio_f(nome);
if (!mio_f.open(QIODevice::ReadOnly)){
size = mio_f.size();
}
@
Why i get the size = 0Thanks Luca
-
You should use '@' balises around your code to make it more readble:
@
QFile mio_f(nome);
if (!mio_f.open(QIODevice::ReadOnly)){
size = mio_f.size();
}
@ -
Qfile::open returns "true" if successful
In your code, your variable size is assignated only if open failed. If it succeeded, your variable isn't touched, it then keeps its previous value (might be 0 depending on compiler and your definition).
Note that documentation doesn't state what size should return on an erronous file, but 0 seems good ;-) -
try this:
@
QFile mio_f(nome);
if (!mio_f.open(QIODevice::ReadOnly))
return; //when file doesnt open.
size = mio_f.size(); //when file does open.@
where 'nome' is a var with the path to file in it || nome is path to file -
The coding style discussion has been moved to "this thread":http://developer.qt.nokia.com/forums/viewthread/4777/.