Created
May 8, 2017 23:22
-
-
Save lighterowl/4a59ac57822f9eea98bc53f49c280758 to your computer and use it in GitHub Desktop.
Serializing and deserializing a QByteArrayList to/from a QDataStream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QByteArray> | |
#include <QByteArrayList> | |
#include <QDataStream> | |
#include <QDebug> | |
#include <QFile> | |
#include <cstring> | |
int main(int argc, char *argv[]) { | |
if (argc != 2) { | |
return 1; | |
} | |
QFile f("foo.bin"); | |
f.open(QIODevice::ReadWrite); | |
QDataStream s(&f); | |
if (::strcmp(argv[1], "read") == 0) { | |
QByteArrayList y; | |
s >> y; | |
qDebug() << y; | |
} else if (::strcmp(argv[1], "write") == 0) { | |
auto x = QByteArrayList{{"\xaa\x55", 2}, {"\xcf", 1}, {"\x00\xff\x80", 3}}; | |
s << x; | |
} else { | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment