Converting QString to Base64
-
wrote on 24 Mar 2020, 20:21 last edited by
Hello,
I am currently facing the problem that I am not able convert a QString to a base64 code. This is my current try:QString filepath = "C:\example.txt";
QFile file(filepath);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString line;
QTextStream in(&file);while(!in.atEnd()){ line.append(in.readLine()); } QString base64 = line; base64.toUtf8().toBase64(); qDebug()<<base64;
The Output is not a base64 code
-
Hi,
What input do you have ?
What output do you expect ?
What output do you get ? -
@Chaki said in Converting QString to Base64:
base64.toUtf8().toBase64();
C++ basics - what do you expect from this line?
-
Hello,
I am currently facing the problem that I am not able convert a QString to a base64 code. This is my current try:QString filepath = "C:\example.txt";
QFile file(filepath);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString line;
QTextStream in(&file);while(!in.atEnd()){ line.append(in.readLine()); } QString base64 = line; base64.toUtf8().toBase64(); qDebug()<<base64;
The Output is not a base64 code
wrote on 24 Mar 2020, 21:42 last edited by@Chaki
When you read https://doc.qt.io/qt-5/qbytearray.html#toBase64 you see:QByteArray QByteArray::toBase64() const
`Returns a copy of the byte array, encoded as Base64.So it is a function returning a result.
-
@Chaki said in Converting QString to Base64:
base64.toUtf8().toBase64();
C++ basics - what do you expect from this line?
wrote on 25 Mar 2020, 06:58 last edited by@Christian-Ehrlicher i thought this line converts a QString to a base64 code
-
Lifetime Qt Championwrote on 25 Mar 2020, 07:03 last edited by Christian Ehrlicher
@Chaki said in Converting QString to Base64:
i thought this line converts a QString to a base64 code
Correct, but the result is thrown away since you don't save the return value - c basics.
-
wrote on 25 Mar 2020, 07:27 last edited by
@Christian-Ehrlicher
Yes you're right sir
Thanks a lot! -
@Christian-Ehrlicher
Yes you're right sir
Thanks a lot!wrote on 25 Mar 2020, 11:13 last edited by@Chaki is your issue solved then? if so please don't forget to mark your post as such!
1/8