QFile.write( myStruct ) - how?

后端 未结 2 1837
滥情空心
滥情空心 2020-12-22 01:14

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

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 02:07

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

    fileheader fh = { ...... };
    QFile f("nanga.dat");
    if(f.open(QIODevice::ReadWrite))
        f.write(reinterpret_cast(&fh), sizeof(fh));
    

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

提交回复
热议问题