質問

I can read bytes from k to k+L from QFile reading first whole file into QByteArray

if (!file.open(QIODevice::ReadOnly))
    //...
    QByteArray blob = file.readAll();
    QByteArray bytes = blob.mid( k, L);

How to read just bytes from k, to k+L, efficiently ?

if (!file.open(QIODevice::ReadOnly))
    //...
    QByteArray bytes = bytesFromFile( file, k, L);
役に立ちましたか?

解決

Use the seek method to get to the position in the file you want to start reading. Then use the read method to read as many bytes as you want from that point.

ie.

if (!file.open(QIODevice::ReadOnly)){
    file.seek(k);
    QByteArray bytes = file.read(L);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top