Gustavo Pinsard Gustavo Pinsard -4 years ago 276
C++ Question

QFile.write( myStruct ) - how?

I'm beginning with Qt and am stuck with a problem supposedly for quite a long time now. I'm sure it's just something I don't see in C++. Anyway, please look at the following simple code and point me what am I doing wrong:

typedef struct FILEHEADER {
char udfSignature[8];
char fileName[64];
long fileVersion;
UNIXTIME fileCreation;
UNIXTIME lastRebuild;
FILEPOINTER descriptor;
} fileheader;

QFile f("nanga.dat");


Qt 5.2.0 trows me the following error message:

C:\sw\udb\udb\main.h:113: error: no matching function for call to

Any suggestion on how I can write this struct to a


Answer Source

QFile has write method which accepts arbitrary array of bytes. You can try something like this:

fileheader fh = { ...... };
QFile f("nanga.dat");
    f.write(reinterpret_cast<char*>(&fh), sizeof(fh));

But remember that in general, it's not a good idea to store any data this way.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download