Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. converting qbyte array to string
Qt 6.12 LTS is out! See what's new in the release blog

converting qbyte array to string

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 2 Posters 9.3k Views
  • 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.
  • jsulmJ jsulm

    @Anna_64 Can you please explain your problem in an understandable way?
    What are x[j] and y[j]?
    Did you check https://doc.qt.io/qt-5/qbytearray.html#fromBase64 ?
    Did you check https://doc.qt.io/qt-5/qstring.html#fromLatin1-1 ?

    A Offline
    A Offline
    Anna_64
    wrote on last edited by
    #3

    @jsulm x[i] and y[j] are the array which is in base 64
    Now i have to convert that into a string and i have to send that into a device for updating x[i] and y[j] contains data that i need to be updated into device so now i have to do conversion to string and finally send data for updation in the below format
    <size>2048</size>
    <Data>x[j]</Data>
    <offset>i.1024</offset>
    <Signature>y[j]<Signature>
    how u understand my question and this s the final stage of the project that is updating data into a device

    jsulmJ 1 Reply Last reply
    0
    • A Anna_64

      @jsulm x[i] and y[j] are the array which is in base 64
      Now i have to convert that into a string and i have to send that into a device for updating x[i] and y[j] contains data that i need to be updated into device so now i have to do conversion to string and finally send data for updation in the below format
      <size>2048</size>
      <Data>x[j]</Data>
      <offset>i.1024</offset>
      <Signature>y[j]<Signature>
      how u understand my question and this s the final stage of the project that is updating data into a device

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Anna_64 I'm still not sure I understand you correctly as neither x[j] not y[j] are Base64 strings.
      Check the links I provided abote to see how de decode Base64 into a QByteArray and then to a string.
      Also, if you want to send it to a device then you don't need to convert it to a string just use the QByteArray you get from fromBase64() method.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Anna_64 I'm still not sure I understand you correctly as neither x[j] not y[j] are Base64 strings.
        Check the links I provided abote to see how de decode Base64 into a QByteArray and then to a string.
        Also, if you want to send it to a device then you don't need to convert it to a string just use the QByteArray you get from fromBase64() method.

        A Offline
        A Offline
        Anna_64
        wrote on last edited by
        #5

        @jsulm
        i had a bin file i converted it into qbyte array and then encoded into base 64 now i have to convert that into a string and send to device x[j] and y[j] are the datas i have

        jsulmJ 1 Reply Last reply
        0
        • A Anna_64

          @jsulm
          i had a bin file i converted it into qbyte array and then encoded into base 64 now i have to convert that into a string and send to device x[j] and y[j] are the datas i have

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @Anna_64 https://doc.qt.io/qt-5/qstring.html#fromLatin1-1

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Anna_64 https://doc.qt.io/qt-5/qstring.html#fromLatin1-1

            A Offline
            A Offline
            Anna_64
            wrote on last edited by
            #7

            @jsulm QString s[64];
            for(int j=0;j<64;j++){
            s[j] ="<UpdateFirmware><Size>2048</Size><Data>"+QByteArray::fromBase64(x[j])+"</Data><Offset>008192</Offset>"+QByteArray::fromBase64(y[j])+"</UpdateFirmware>";
            i have converted my q byte array of base 64 and s[j] should be sent into my device but its showing error

            jsulmJ 1 Reply Last reply
            0
            • A Anna_64

              @jsulm QString s[64];
              for(int j=0;j<64;j++){
              s[j] ="<UpdateFirmware><Size>2048</Size><Data>"+QByteArray::fromBase64(x[j])+"</Data><Offset>008192</Offset>"+QByteArray::fromBase64(y[j])+"</UpdateFirmware>";
              i have converted my q byte array of base 64 and s[j] should be sent into my device but its showing error

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @Anna_64 said in converting qbyte array to string:

              showing error

              if you get an error you should post it here...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Anna_64 said in converting qbyte array to string:

                showing error

                if you get an error you should post it here...

                A Offline
                A Offline
                Anna_64
                wrote on last edited by
                #9

                @jsulm :-1: Fehler: cannot open output file debug\instal.exe: Permission denied
                2.collect2.exe:-1: Fehler: error: ld returned 1 exit status

                jsulmJ 1 Reply Last reply
                0
                • A Anna_64

                  @jsulm :-1: Fehler: cannot open output file debug\instal.exe: Permission denied
                  2.collect2.exe:-1: Fehler: error: ld returned 1 exit status

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #10

                  @Anna_64 said in converting qbyte array to string:

                  instal.exe

                  what is this? Is it you app?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Anna_64 said in converting qbyte array to string:

                    instal.exe

                    what is this? Is it you app?

                    A Offline
                    A Offline
                    Anna_64
                    wrote on last edited by
                    #11

                    @jsulm yes

                    jsulmJ 1 Reply Last reply
                    0
                    • A Anna_64

                      @jsulm yes

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @Anna_64 Is it possible that your app is still being executed when you try to build? Stop/kill the running instance and build again. Windows does not allow write access to open/locked files.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @Anna_64 Is it possible that your app is still being executed when you try to build? Stop/kill the running instance and build again. Windows does not allow write access to open/locked files.

                        A Offline
                        A Offline
                        Anna_64
                        wrote on last edited by
                        #13

                        @jsulm Thank You it works now

                        A 1 Reply Last reply
                        0
                        • A Anna_64

                          @jsulm Thank You it works now

                          A Offline
                          A Offline
                          Anna_64
                          wrote on last edited by
                          #14

                          @Anna_64 {
                          QByteArray uq;
                          uq.resize(7);
                          uq[0] = 0xAA;
                          uq[1] = 0x55;
                          uq[2] = 0x04;
                          uq[3] = 0x00;
                          uq[4] = 0x00;
                          uq[5] = 0xC0;
                          uq[6] = 0xBB;
                          serial->write(uq);
                          after this write command i have to close serial port and wait for 5 sec and open serial port and send data so after
                          serial->write(uq);
                          serial->close();
                          QThread::sleep(5);but it gives error like device not opened

                          1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Anna_64 Can you please explain your problem in an understandable way?
                            What are x[j] and y[j]?
                            Did you check https://doc.qt.io/qt-5/qbytearray.html#fromBase64 ?
                            Did you check https://doc.qt.io/qt-5/qstring.html#fromLatin1-1 ?

                            A Offline
                            A Offline
                            Anna_64
                            wrote on last edited by
                            #15

                            @jsulm QByteArray uq;
                            uq.resize(7);
                            uq[0] = 0xAA;
                            uq[1] = 0x55;
                            uq[2] = 0x04;
                            uq[3] = 0x00;
                            uq[4] = 0x00;
                            uq[5] = 0xC0;
                            uq[6] = 0xBB;
                            serial->write(uq);
                            after this write command i have to close serial port and wait for 5 sec and open serial port and send data so after
                            serial->write(uq);
                            serial->close();
                            QThread::sleep(5);but it gives error like device not opened

                            jsulmJ 1 Reply Last reply
                            0
                            • A Anna_64

                              @jsulm QByteArray uq;
                              uq.resize(7);
                              uq[0] = 0xAA;
                              uq[1] = 0x55;
                              uq[2] = 0x04;
                              uq[3] = 0x00;
                              uq[4] = 0x00;
                              uq[5] = 0xC0;
                              uq[6] = 0xBB;
                              serial->write(uq);
                              after this write command i have to close serial port and wait for 5 sec and open serial port and send data so after
                              serial->write(uq);
                              serial->close();
                              QThread::sleep(5);but it gives error like device not opened

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #16

                              @Anna_64 You should first wait until data was written before calling close(). See https://doc.qt.io/qt-5/qserialport.html#waitForBytesWritten

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              A 1 Reply Last reply
                              2
                              • jsulmJ jsulm

                                @Anna_64 You should first wait until data was written before calling close(). See https://doc.qt.io/qt-5/qserialport.html#waitForBytesWritten

                                A Offline
                                A Offline
                                Anna_64
                                wrote on last edited by
                                #17

                                @jsulm how to write code this
                                after serial->write(uq)
                                how to introduce a wait for 5 seconds and close serial port

                                jsulmJ 1 Reply Last reply
                                0
                                • A Anna_64

                                  @jsulm how to write code this
                                  after serial->write(uq)
                                  how to introduce a wait for 5 seconds and close serial port

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #18

                                  @Anna_64 https://doc.qt.io/qt-5/qtimer.html#singleShot

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  A 1 Reply Last reply
                                  0
                                  • jsulmJ jsulm

                                    @Anna_64 https://doc.qt.io/qt-5/qtimer.html#singleShot

                                    A Offline
                                    A Offline
                                    Anna_64
                                    wrote on last edited by
                                    #19

                                    @jsulm QString s[64];
                                    QString test ="";
                                    QByteArray testfinal;
                                    testfinal.resize(65000);
                                    for(int j=0;j<64;j++)
                                    {
                                    QString offsetAddress=QString::number(j*1024).rightJustified(6, '0');
                                    s[j] = "<UpdateFirmware><Size>2048</Size><Data>"+x[j]+"</Data><Offset>"+offsetAddress+"</Offset><Signature>"+y[j]+"</Signature></UpdateFirmware>";
                                    //s[j] ="<UpdateFirmware><Size>2048</Size><Data>"+x[j]+"</Data><Offset>008192</Offset><Signature>"+y[j]+"</Signature></UpdateFirmware>";
                                    if(j>=8){
                                    testfinal+=s[j];
                                    serial->write(testfinal);
                                    }
                                    i am trying to send this string message to my device and do updation but only 15% updation s happening theres no error as well but with testing i found complete updation s not happening
                                    can u plz figure it which part of data not working i guess it s the offset adress part

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • A Anna_64

                                      @jsulm QString s[64];
                                      QString test ="";
                                      QByteArray testfinal;
                                      testfinal.resize(65000);
                                      for(int j=0;j<64;j++)
                                      {
                                      QString offsetAddress=QString::number(j*1024).rightJustified(6, '0');
                                      s[j] = "<UpdateFirmware><Size>2048</Size><Data>"+x[j]+"</Data><Offset>"+offsetAddress+"</Offset><Signature>"+y[j]+"</Signature></UpdateFirmware>";
                                      //s[j] ="<UpdateFirmware><Size>2048</Size><Data>"+x[j]+"</Data><Offset>008192</Offset><Signature>"+y[j]+"</Signature></UpdateFirmware>";
                                      if(j>=8){
                                      testfinal+=s[j];
                                      serial->write(testfinal);
                                      }
                                      i am trying to send this string message to my device and do updation but only 15% updation s happening theres no error as well but with testing i found complete updation s not happening
                                      can u plz figure it which part of data not working i guess it s the offset adress part

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #20

                                      @Anna_64 Sorry, I don't understand your question. What does not work? Sending data to device?

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      A 1 Reply Last reply
                                      0
                                      • jsulmJ jsulm

                                        @Anna_64 Sorry, I don't understand your question. What does not work? Sending data to device?

                                        A Offline
                                        A Offline
                                        Anna_64
                                        wrote on last edited by
                                        #21

                                        @jsulm i am sending some data to a device but its not workingqbytearray to qstring s creating some issues inside the loop
                                        in my above code
                                        testfinal+=s[j];
                                        this section s producing some issues

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt
                                        • Unsolved