Truncate a file under mac with Qt
-
Hello under linux if i have tru truncate a file i use :
truncate "file.xxx" --size mysizenow i'm under mac and the truncate don't work, i can do it using Qt?
Thanks
Luca
-
@QFile f(<Path to File>);
if (f.open(QIODevice::Truncate | QIODevice::WriteOnly)) {
//f is now empty and opened for writing
}@ -
but where i specify the file size.
Luca
-
truncate always clears everything, like in SQL Truncate table also removes all rows.
-
Have you tried to open the QFile docs and look for "truncate"?
-
"QFile::resize() ":http://doc.qt.nokia.com/4.7/qfile.html#resize (or its static equivalent) should be your friend.
-
Just for info the file must be open in read mode o only in write or in read and write?
Thanks
Luca -
From a quick look into the sources, it seems that it doesn't matter whether the file is open.
To be on the safe side: try yourself - which would lead to the quickest answer, instead of waiting for a forum reply, BTW :-)
-
Hello again
i have write this :
@QFileInfo info_file(myfile);
long long lgqt = info_file.size();
QFile mfile(nome_f);
@
if i insert a breack point when o try to go to the line :
long long lgqt = info_file.size(); i get the error :
cannot continue debugged process:
Warning:
cannot inster breackpoint -101
Error accessing memory address xxxxxxx input/output error.
But if i insert the breackpoint for example on the line "QFile mfile(nome_f);" e get no error and also i get the file size
Why?Luca
-
The code is basically ok. It seems that it is broken otherwise.
The snippet lacks complete information, though. We're not able to analyze it otherwise.
Of what type is myfile? Where is it defined?