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. [SOLVED]How to store short in a QByteArray?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to store short in a QByteArray?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 10.0k Views 1 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.
  • S Offline
    S Offline
    shoyeb
    wrote on last edited by
    #4

    @qxoz, thanx for your reply.
    i will try this and let u know.
    thnx again.

    There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shoyeb
      wrote on last edited by
      #5

      hey i tried this...

      @QByteArray ba((const char*)m_output.data(), sizeof(ushort));
      playbackBuffer.append(ba);@

      but i got this error...

      error: passing 'const QByteArray' as 'this' argument of 'QByteArray& QByteArray::append(const QByteArray&)' discards qualifiers [-fpermissive]

      and one thing my "playbackBuffer" is of type const QByteArray.

      There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #6

        Ubuntu? add fpermissive to project CFLAGS:
        @QMAKE_CXXFLAGS = -fpermissive@
        don't forget to run qmake after editing .pro file

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shoyeb
          wrote on last edited by
          #7

          hey thanx for ur reply..

          but i dont want to use this flag, basically this flag is going to suppress the error which m getting and i want to fix my code.

          please help me with this..

          There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #8

            this is not error, it's a warning... calling const instance functions is ok, but dangerous if you don't exactly know what are you doing, thats because gcc warns you about that.
            Ubuntu patched gcc has been modified to treat this warning as error... So, you will be just warned with vanilla gcc and compilation will success. It's all on you how to fix this issue...

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on last edited by
              #9

              so long the “playbackBuffer” is of type const QByteArray, you will getting this warning.

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shoyeb
                wrote on last edited by
                #10

                but i am getting this as an error not warning..
                so how do i fix it.

                There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  AcerExtensa
                  wrote on last edited by
                  #11

                  I've told you

                  bq. Ubuntu patched gcc has been modified to treat this warning as error…

                  add
                  @QMAKE_CXXFLAGS = -fpermissive@
                  to project file or redesign your code...

                  God is Real unless explicitly declared as Integer.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    shoyeb
                    wrote on last edited by
                    #12

                    hey thanx for the precious time u gave for my error...

                    but i made it work without setting the flag....

                    like this...

                    @const QByteArray ba((const char*)m_output.data(), sizeof(ushort));
                    const_cast<QByteArray &>(playbackBuffer).append(ba);
                    @

                    thanx once again...

                    [EDIT: code formatting, Volker]

                    There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      shoyeb
                      wrote on last edited by
                      #13

                      @QByteArray ba((const char*)m_output.data(), sizeof(ushort));
                      const_cast<QByteArray &>(playbackBuffer).append(ba);@

                      There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

                      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 Extensions
                      • Unsolved