QImage img = pix.toImage(); QByteArray ba; QBuffer buf(&ba); img.save(&buf, "png"); QString base64String = ba.toBase64();