1

I was wondering why :

QString MainWindow::getFileText(QString filename)
{
    QFile test(filename + ".txt"); // The file who gets written into
    QFile file(filename);  // The executable I am reading
    QDataStream in(&test);
    if(!test.open(QIODevice::WriteOnly))
        return "";
    if(!file.open(QIODevice::ReadOnly))
       return "";
    qDebug() << file.read(257);        // Got me the output I am wanting to write in my QDataStream
    in.writeRawData(file.read(257), 257); // It is writing another value
    file.close();
    test.close();
    return "";
}

with my file.exe was giving me this output, through qDebug() :

MZP\x00\x02\x00\x00\x00\x04\x00\x0F\x00\xFF\xFF\x00\x00\xB8\x00\x00\x00\x00\x00\x00\x00@\x00\x1A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xBA\x10\x00\x0E\x1F\xB4\t\xCD!\xB8\x01L\xCD!\x90\x90This program must be run under Win32\r\n$7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00P

whereas my .txt gets another value.

If I copy paste the output just above and write

in.writeRawData("the output...", 257);

instead, it works perfectly. So I guess qDebug() is doing a conversion, but which one ?

Thanks in advance

Nox
  • 713
  • 7
  • 16
  • 2
    Doesn't the second `file.read(257)` read next 257 bytes starting from 258 till 514? That is why the debug output and .txt file differ. – 273K Nov 15 '19 at 05:17
  • That was it. Thank you for the quick answer ! – Nox Nov 15 '19 at 05:22

0 Answers0