Well,I have tried many different combination with different syntax...I cannot post a certain code,as there were many things I tried..
Can you please post a working piece?
Well,I have tried many different combination with different syntax...I cannot post a certain code,as there were many things I tried..
Can you please post a working piece?
Post the the code you thought was the best of the things you tried, and we can pick it up from there.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Sure.
Well I made this:Qt Code:
#include <QtCore/QCoreApplication> #include <QFile> #include <QDebug> int main(int argc, char *argv[]) { if( !f.exists() ) { // It does not exist qDebug() << "The file does not exist.\n"; } // It exists, open it { // It could not open qDebug() << "Failed to open."; return 0; } // It opened, now we need to close it qDebug() << "Success"; int size = f.size(); qDebug() << "size: " << size; char * buffer; uint u = sizeof(f); data.readBytes(buffer,u); f.close(); return a.exec(); }To copy to clipboard, switch view to plain text mode
Then I thought that I may need to make a loop,in order to read a byte after byte..but still nothing.
The code doesn't make much sense really. Why don't you just use QIODevice::read() on your QFile object?
Sorry,
Qt Code:
int main(int argc, char *argv[]) { .... int size = f.size(); qDebug() << "size: " << size; char * buffer; uint u = sizeof(f); data.readBytes(buffer,u); f.close(); return a.exec(); }To copy to clipboard, switch view to plain text mode
what you're doing??
- You're using a pointer "buffer" as array of bytes (WRONG)
- You're using sizeof of an object as amount of data to read (WRONG)
for 1. it's strange that your program doesn't crash
I suggest you
Qt Code:
int size = f.size(); qDebug() << "size: " << size; To copy to clipboard, switch view to plain text mode
and use directly "buffer"
Last edited by mcosta; 19th April 2011 at 16:07. Reason: updated contents
A camel can go 14 days without drink,
I can't!!!
Bookmarks