Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get a base64 of a base64 encoding inside a string?



  • I have a base 64 inside a string, but my object is a Qstring I need to take it to a QByteArray but without losing the value of base 64

    example:

    QString var =("b'L4m2aeeFG8vNnsFUEsBAhQDFAAAAAgAAAAhAPoTdNRkAQAANwcAABMAAAAAAAAAAAAAAAAAAAAAAFtDb250ZW50X1R5cGVzXS54bWxQSwECFAMUAAAACAAAACEA8p9J2ukAAABLAgAACwAAA' ")

    QByteArray filecontent_pfo = QByteArray::fromBase64(var.toUtf8());

    but at the moment this doesn't give me the wishes.



  • @Ripley said in How to get a base64 of a base64 encoding inside a string?:

    QString var =("b'L4m2aeeFG8vNnsFUEsBAhQDFAAAAAgAAAAhAPoTdNRkAQAANwcAABMAAAAAAAAAAAAAAAAAAAAAAFtDb250ZW50X1R5cGVzXS54bWxQSwECFAMUAAAACAAAACEA8p9J2ukAAABLAgAACwAAA' ")
    

    Do you mean you just need to take off the leading b' and trailing ' (plus spaces) and then treat that (via QByteArray::QByteArray(const char *data, int size = -1) if necessary, don't know if you need that, the QString after the removal should do?) as the QByteArray value to pass to QByteArray QByteArray::fromBase64(const QByteArray &base64)?



  • @JonB Yes, i get the variable as a binary decode this as base64 from the server which sent me this example that is var. My real problem is that this example is a xlsx sheet and knowing not how to decode this. Just var is a little example.


  • Qt Champions 2019



  • @Ripley
    I suggested what you need to do in my first reply. You have a string which looks like "b'...' ". You need to strip off the leading & trailing markers before passing to QByteArray::fromBase64().


Log in to reply