QFile read(to, 65535) returns -1 on Windows 7/VS2010, works on linux
Very simple:
1) pBuffer is char array (65535) long
2) file on disk is 8589 bytes
3) read returns -1 so qFatal in the tiny example gets executed - but why? If another value is put there, 20000 for example works (Size == 8589), 50000 returns -1 :(
Code:
qDebug() << "Fail";
return false;
}
qint64 Size = read(pBuffer, 65535); // The maximum number (looks like a hard number) what works is 38002
if (Size == -1) {
qFatal("Why?");
}
Re: QFile read(to, 65535) returns -1 on Windows 7/VS2010, works on linux
"read returns -1 so qFatal in the tiny example gets executed - but why"
You are executing a function "read" from whatever source, but not File.read() that you probably want to...
Re: QFile read(to, 65535) returns -1 on Windows 7/VS2010, works on linux
Okay, the code example was a little bit edited before putting here so, it is correctly:
Code:
qDebug() << "Fail";
return false;
}
qint64 Size = File.read(pBuffer, 65535); // The maximum number (looks like a hard number) what works is 38002
if (Size == -1) {
qFatal("Why?");
}
The question is the same, why does it fail on Windows 7?
Re: QFile read(to, 65535) returns -1 on Windows 7/VS2010, works on linux
Even if you use the Windows API ReadFile function, it performs differently on XP vs W7.
So the only advice is to not try and read more bytes than are available to be read (eg. get the file size first and only read that many bytes)