I have this code:
int *size1 = new int();
int *size2 = new int();
QFile* file = new QFile("C:/Temp/tf.txt");
file->open(QFile::WriteOnly | QFile::Truncate);
file->write(str);
*size1 = file->size();
file->close();
file->open(QFile::WriteOnly | QFile::Truncate);
file->write(strC);
*size2 = file->size();
file->close();
delete file;
if (size1 < size2)
{
return true;
}
else
{
return false;
}
delete size1;
delete size2;
I want to compare bytes in file. But it comparing number of symbols in file.
According to Qt's docs:
qint64 QFile::size () const [virtual]
Reimplemented from QIODevice::size().
Returns the size of the file.
For regular empty files on Unix (e.g. those in /proc), this function returns 0; the contents of such a file are generated on demand in response to you calling read().
It does return the number of bytes, not the number of characters (I'm assuming that's what you mean by "symbols". Note that size() returns a qint64, not an int.
Your code should work as expected if you use a qint64.
Also, why are you using pointers for int? There is no benefit in doing that, just create it on the stack:
qint64 size1 = 0;
qint64 size2 = 0;