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 Qbyte array to array and to double
Qt 6.11 is out! See what's new in the release blog

Converting Qbyte array to array and to double

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 1.2k 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.
  • D Offline
    D Offline
    dziko147
    wrote on last edited by
    #3

    @artwaw thanks for your reply . Ok I will remove the Qstring .

    Also I get unreadable data like " 3.13891e-43 " for a array "0xff000000e0" .

    I use a online converter and give the same value .

    But there is a way to make it readable .

    thank you

    artwawA 1 Reply Last reply
    0
    • D dziko147

      @artwaw thanks for your reply . Ok I will remove the Qstring .

      Also I get unreadable data like " 3.13891e-43 " for a array "0xff000000e0" .

      I use a online converter and give the same value .

      But there is a way to make it readable .

      thank you

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #4

      @dziko147
      again: in the "else" part you have

      qDebug()  << "this is data"<< myDatadouble;
      QString DatatoString =QString::number(myData);
      

      where I think you should have

      qDebug()  << "this is data"<< myDatadouble;
      QString DatatoString =QString::number(myDatadouble);
      

      since you do not even set myData in that part. Hence your string contains rubbish, you don't even initialise the variable.

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dziko147
        wrote on last edited by
        #5

        @artwaw yes in my code I have

        qDebug()  << "this is data"<< myDatadouble;
        QString DatatoString =QString::number(myDatadouble);
        

        just when i copying it i I was mistaken .

        I update my topic :)

        1 Reply Last reply
        0
        • D dziko147

          Hello , I get some data from a CAN Bus . So my data is some float and some double .

          What I did is :

          float myData;
          double myDatadouble;
          
                             QDataStream stream(data);
                              qDebug() << data.size() << " Data Data&size" ;
                             
                              if (data.size()== 5){
                                 quint8 byte;
                                  stream >> byte; // skip first byte
                        stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
                                  stream >> myData; // read data
                                  qDebug()  << "this is data"<< myData ;
                                  QString DatatoString =QString::number(myData);
                                  Outputs[i]=DatatoString;
                              qDebug() << "In outputs data" << Outputs[i];
                              }
          else {
          
                             quint8 byte;
                              stream >> byte; // skip first byte
                                  stream.setFloatingPointPrecision(QDataStream::DoublePrecision);
                               stream >> myDatadouble; // read data
                              qDebug()  << "this is data"<< myDatadouble;
                              QString DatatoString =QString::number(myDatadouble);
                              Outputs[i]=DatatoString;
                              qDebug() << "In outputs data" << Outputs[i];
                              }              
                             
          
          

          I get only float converted , the double is usually "0" .

          thankyou

          CP71C Offline
          CP71C Offline
          CP71
          wrote on last edited by CP71
          #6

          @dziko147
          Hi,
          you have checked only if (data.size()== 5) in first if,
          Did you check in else that the data size is correct?
          I think no

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dziko147
            wrote on last edited by
            #7

            @CP71 yes it return a size :8 byte

            CP71C 1 Reply Last reply
            0
            • D dziko147

              @CP71 yes it return a size :8 byte

              CP71C Offline
              CP71C Offline
              CP71
              wrote on last edited by
              #8

              @dziko147
              8! so doesn't you have a one spare byte in else as in float case?

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dziko147
                wrote on last edited by dziko147
                #9

                @CP71 said in Converting Qbyte array to array and to double:

                8! so doesn't you have a one spare byte in else as in float case?

                no I usually get frame started with FF .

                I mean than in the case of a float I get "FF + 4Byte data"

                In the case of a Double I get "FF +7Byte data "

                and here I skip the first byte

                                   quint8 byte;
                                    stream >> byte; // skip first byte
                
                CP71C 1 Reply Last reply
                0
                • D dziko147

                  @CP71 said in Converting Qbyte array to array and to double:

                  8! so doesn't you have a one spare byte in else as in float case?

                  no I usually get frame started with FF .

                  I mean than in the case of a float I get "FF + 4Byte data"

                  In the case of a Double I get "FF +7Byte data "

                  and here I skip the first byte

                                     quint8 byte;
                                      stream >> byte; // skip first byte
                  
                  CP71C Offline
                  CP71C Offline
                  CP71
                  wrote on last edited by CP71
                  #10

                  @dziko147 said in Converting Qbyte array to array and to double:

                  In the case of a Double I get "FF +7Byte data "

                  Sorry, but in double case I think you'd send 0xFF+8bytes, anyway I think your application tries read a double at 8 bytes

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dziko147
                    wrote on last edited by
                    #11

                    @CP71 you are right :D

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dziko147
                      wrote on last edited by
                      #12

                      @CP71 now how can make it readable .
                      For example I get " 3.13891e-43 " for a array "0xff000000e0" .
                      please

                      CP71C 1 Reply Last reply
                      0
                      • D dziko147

                        @CP71 now how can make it readable .
                        For example I get " 3.13891e-43 " for a array "0xff000000e0" .
                        please

                        CP71C Offline
                        CP71C Offline
                        CP71
                        wrote on last edited by
                        #13

                        @dziko147
                        It is wrong!

                        https://www.binaryconvert.com/convert_double.html

                        As last time, I must go.
                        Sorry, bye

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dziko147
                          wrote on last edited by
                          #14

                          @CP71 as u like bro good bye

                          1 Reply Last reply
                          1

                          • Login

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