Qt C++ read a whole file into memory

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...");


blog comments powered by Disqus

This ClearEvo.com blog is powered by Debian GNU/Linux, running lighttpd, generated using jekyll on Ubuntu.

Subscribe for new updates