Qt C++ read a whole file into memory

less than 1 minute read

Published:

Sometimes you just want to get that whole file into a buffer for quick use:

QFile file(abs_path);

    if(file.open(QIODevice::ReadOnly))
    {
        QByteArray bytes = file.readAll();
        file.close();
        main_template = bytes;
        qDebug(main_template.toAscii());
    }
    else
	qDebug("rfile failed...");

Leave a Comment