File size
-
wrote on 28 Mar 2011, 16:36 last edited by
@
QFile mio_f(nome);
if (!mio_f.open(QIODevice::ReadOnly)){
size = mio_f.size();
}
@
Why i get the size = 0Thanks Luca
-
wrote on 28 Mar 2011, 16:41 last edited by
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();
}
@ -
wrote on 28 Mar 2011, 16:45 last edited by
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 ;-) -
wrote on 28 Mar 2011, 17:36 last edited by
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 -
wrote on 28 Mar 2011, 20:27 last edited by
The coding style discussion has been moved to "this thread":http://developer.qt.nokia.com/forums/viewthread/4777/.
1/5