I have my files as input in my app (its a binary file). What i want to do is read the whole file and put it in a QVector <uchar> mydata. is there an easy way to do it in Qt?
please help me,
baray98
I have my files as input in my app (its a binary file). What i want to do is read the whole file and put it in a QVector <uchar> mydata. is there an easy way to do it in Qt?
please help me,
baray98
You can do it with a QFile and a QDataStream:
Qt Code:
return; char *s = new char[(int)f.size()]; stream.readRawData(s, (int)f.size());To copy to clipboard, switch view to plain text mode
Now all the data is in s. Keep in mind that for big files you may get out of memory errors(new might fail) so the solution is to read the file in smaller buffers and process them sequentially.
QVector<uchar> is not really optimal in this case so you should use a plain char array.
Or a QByteArray in a bit simpler way:
Qt Code:
To copy to clipboard, switch view to plain text mode
Bookmarks