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. Adding QByteArray
Qt 6.11 is out! See what's new in the release blog

Adding QByteArray

Scheduled Pinned Locked Moved General and Desktop
20 Posts 5 Posters 14.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #8

    Unhandled exception at 0x75eb9673 in app.exe= Microsoft C++ exception: std::bad_alloc at memory location 0x001dc99c..
    [quote author="1+1=2" date="1335906112"]
    [quote author="christopher09" date="1335905550"]Yes, but its not working.
    [/quote]
    So, how do you come to this conclusion?[/quote]

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

      [quote author="christopher09" date="1335912902"]Unhandled exception at 0x75eb9673 in app.exe= Microsoft C++ exception: std::bad_alloc at memory location 0x001dc99c..
      [/quote]

      I don't think above code will cause such an exception. what you need is: debug your application.

      In additon, you can play with examples like this:
      @
      #include <QtCore>

      int main()
      {
      QByteArray x("\x01\x02\x03\x04"), y("\x05\x06\x07");

      QByteArray z;
      for(int k=0;k<qMin(x.size(), y.size());k++){
           z.append(x[k]+y[k]);
      }
      
      qDebug()<<z.toHex();
      return 0;
      

      }
      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #10

        On compiling, Unhandled exception at 0x00c90364 in app.exe: 0xC0000005: Access violation reading location 0x00141934.
        [quote author="1+1=2" date="1335913456"]
        [quote author="christopher09" date="1335912902"]Unhandled exception at 0x75eb9673 in app.exe= Microsoft C++ exception: std::bad_alloc at memory location 0x001dc99c..
        [/quote]

        I don't think above code will cause such an exception. what you need is: debug your application.

        In additon, you can play with examples like this:
        @
        #include <QtCore>

        int main()
        {
        QByteArray x("\x01\x02\x03\x04"), y("\x05\x06\x07");

        QByteArray z;
        for(int k=0;k<qMin(x.size(), y.size());k++){
             z.append(x[k]+y[k]);
        }
        
        qDebug()<<z.toHex();
        return 0;
        

        }
        @[/quote]

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

          Obviously, what you given is a runtime error instead of compile errors.

          If you are sure that above example will cause this exception under your environment, please debug it first and tell us which line trigger the exception.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #12

            I am writing the binary files using following method.

            @
            //....
            typedef std::basic_ofstream<unsigned char, std::char_traits<unsigned char> > uofstream;
            uofstream op(filename, ios::out | ios::binary);
            op.write(size, 5);
            op.write(RGrBl, widthheight3);
            op.write(a,widthheightdifference);/difference is int size[4]
            op.close();
            @

            I want to add the values at each BYTE in the files created by above function. I am unable to write it because of exception at run time saying bad memory allocation, and referring to mlock.c

            I just want to add the hex values at all the bytes but I am getting exceptions at time saying bad memory allocation and referring to mlock.c. I am using

            @
            //x and y are read from files created using the above
            QByteArray alpha; for(int k=0;k<qMin(x.size(), y.size());k++){ alpha.append(x[k]-y[k]); } qDebug()<<z.toHex();
            QByteArray beta; for(int j=0;j<qMin(x.size(),alpha.size());++j) { alpha.append(x[j]+z[j]); } qDebug()<<beta.toHex();
            @

            What could be wrong in this ?
            Thanks

            [EDIT: code formatting, Volker]

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #13

              Please use @-tags for your code snippets or click on the code icon (the rightmost icon) in the editor. This way your code is formatted nicely and your chances that anyone takes care of what your write are much higher.

              I've added them for you a last time.

              Thanks.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #14

                I have to wonder: what do you hope to achieve by adding together values from two binary files who's formats you don't know? Who or what is supposed to use and make sense of the resulting file afterwards? And are you sure you want to just add two chars? How do you deal with overflows?

                It just looks generally weird to me.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #15

                  I am basically extracting the difference between a original image and the the image I could save to the disk. So, the difference when added to the original should give the file without any difference.
                  [quote author="Andre" date="1336045803"]I have to wonder: what do you hope to achieve by adding together values from two binary files who's formats you don't know? Who or what is supposed to use and make sense of the resulting file afterwards? And are you sure you want to just add two chars? How do you deal with overflows?

                  It just looks generally weird to me. [/quote]

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #16

                    So... you're trying to create some kind of patch file for a binary file?

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #17

                      Yes in a way. A patch with difference is created and added to the original to remove the disparity in output image.
                      [quote author="Andre" date="1336048685"]So... you're trying to create some kind of patch file for a binary file?[/quote]

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #18

                        What's the use of doing that? Note that your way of patching will only work if both files have the same size, and will produce files that have the same size as the original. I really fail to see the point of this excersise.

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #19

                          They'll be all the time.To keep it simple, it may be said that an encryption is patched to make it lossless.
                          [quote author="Andre" date="1336050201"]What's the use of doing that? Note that your way of patching will only work if both files have the same size, and will produce files that have the same size as the original. I really fail to see the point of this excersise.[/quote]

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #20

                            You really lost me. If you want file encryption, I think there are better ways. Good luck with your project though!

                            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