Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Converting QString to Base64
Forum Updated to NodeBB v4.3 + New Features

Converting QString to Base64

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 6.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chaki
    wrote on 24 Mar 2020, 20:21 last edited by
    #1

    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

    J 1 Reply Last reply 24 Mar 2020, 21:42
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Mar 2020, 21:06 last edited by
      #2

      Hi,

      What input do you have ?
      What output do you expect ?
      What output do you get ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 24 Mar 2020, 21:29 last edited by
        #3

        @Chaki said in Converting QString to Base64:

        base64.toUtf8().toBase64();

        C++ basics - what do you expect from this line?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        C 1 Reply Last reply 25 Mar 2020, 06:58
        4
        • C Chaki
          24 Mar 2020, 20:21

          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

          J Offline
          J Offline
          JonB
          wrote on 24 Mar 2020, 21:42 last edited by
          #4

          @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.

          1 Reply Last reply
          5
          • C Christian Ehrlicher
            24 Mar 2020, 21:29

            @Chaki said in Converting QString to Base64:

            base64.toUtf8().toBase64();

            C++ basics - what do you expect from this line?

            C Offline
            C Offline
            Chaki
            wrote on 25 Mar 2020, 06:58 last edited by
            #5

            @Christian-Ehrlicher i thought this line converts a QString to a base64 code

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 25 Mar 2020, 07:03 last edited by Christian Ehrlicher
              #6

              @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.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              4
              • C Offline
                C Offline
                Chaki
                wrote on 25 Mar 2020, 07:27 last edited by
                #7

                @Christian-Ehrlicher
                Yes you're right sir
                Thanks a lot!

                P 1 Reply Last reply 25 Mar 2020, 11:13
                0
                • C Chaki
                  25 Mar 2020, 07:27

                  @Christian-Ehrlicher
                  Yes you're right sir
                  Thanks a lot!

                  P Offline
                  P Offline
                  Pablo J. Rogina
                  wrote on 25 Mar 2020, 11:13 last edited by
                  #8

                  @Chaki is your issue solved then? if so please don't forget to mark your post as such!

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0

                  1/8

                  24 Mar 2020, 20:21

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved