How to read n bytes of a file?(QT C++)
-
Hi im new to Qt and im trying to read for example the first 4 bytes of my .txt file and show it. I've been searching and figure that QbyteArray may help me best in this situation. so I really like to know how can i read the first 4 bytes of my file with QbyteArray? (appreciate if u write any example code)
-
Open the file and then call QFile::read() with the number of bytes you want to read.
-
actually im try and i think i did it wrong. could you edit the correct code?
my code:QString File_Name = QFileDialog::getOpenFileName(this, "open the file name", QDir::homePath()); QByteArray data; QFile File2(File_Name); File2.open(QIODevice::ReadOnly | QFile::Text);
I want to read 4 bytes of File2.
-
actually im try and i think i did it wrong. could you edit the correct code?
my code:QString File_Name = QFileDialog::getOpenFileName(this, "open the file name", QDir::homePath()); QByteArray data; QFile File2(File_Name); File2.open(QIODevice::ReadOnly | QFile::Text);
I want to read 4 bytes of File2.
@amin_nekounaam said in How to read n bytes of a file?(QT C++):
I want to read 4 bytes of File2.
And what's the problem - as I said above use QFile::read() for this task.
And you should check the return value of QFile::open() -
@amin_nekounaam said in How to read n bytes of a file?(QT C++):
I want to read 4 bytes of File2.
And what's the problem - as I said above use QFile::read() for this task.
And you should check the return value of QFile::open()@Christian-Ehrlicher said in How to read n bytes of a file?(QT C++):
Thanks got it. Solved.
-
@Christian-Ehrlicher said in How to read n bytes of a file?(QT C++):
Thanks got it. Solved.
@amin_nekounaam Then also mark this topic as solved, thx.