I did try to open the buffer (and close it). QByteArray ba; QBuffer bu(&ba); //bu.open(QBuffer::ReadWrite); bu.open(QIODevice::WriteOnly); image.save(&bu, "PNG"); //bu.close(); //QString imgBase64 = ba.toBase64(); QString imgBase64 = QString::fromLatin1(ba.toBase64().data()); qDebug() << "image base64: " << imgBase64; qDebug can't show the base64 string for some reason because std::cout << imgBase64.toStdString(); prints the correct base64 string. I did try serval version of code before i posted here. If i read the png from file and get a base64 from it, the same happens without the buffer. qDebug won't print out the base64 string. QByteArray ba; ba = file2.readAll().toBase64(); qDebug() << "base64 from png: " << ba.data(); // nothing std::cout << ba.data(); // works I wonder why.