Skip to content

Instantly share code, notes, and snippets.

@BriFuture
Created March 24, 2019 07:11
Show Gist options
  • Save BriFuture/d9d7b153e2c5d3bacdeb1302668553ca to your computer and use it in GitHub Desktop.
Save BriFuture/d9d7b153e2c5d3bacdeb1302668553ca to your computer and use it in GitHub Desktop.
QFile map file into memory
#include <QCoreApplication>
#include <QFile>
#include <QDir>
#define Size 150 * 2096
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QDir dir;
dir.mkdir("video");
QString fileName = dir.absoluteFilePath("video/test.dat");
QFile file(fileName);
file.open(QFile::ReadWrite);
uchar colors[Size];
for(int i = 0; i < Size; i++) {
colors[i] = uchar(i);
}
file.resize(Size);
uchar *filemap = file.map(0, Size);
memcpy(filemap, colors, Size);
file.unmap(filemap);
file.close();
return 0;
// return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment