Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. What can we do with QBitArray?
Forum Updated to NodeBB v4.3 + New Features

What can we do with QBitArray?

Scheduled Pinned Locked Moved C++ Gurus
9 Posts 4 Posters 6.4k 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.
  • I Offline
    I Offline
    ibingow
    wrote on last edited by
    #1

    std::bitset has to_ulong() and to_string() members, they are very useful. QBitArray has none of them. I think i can't do any thing using QBitArray.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Well, you get the advantages you'll get with every Qt container: implicit sharing, QDataStream support, dynamic sizing.

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

        [quote author="ibingow" date="1325065025"] std::bitset has to_ulong() and to_string() members, they are very useful. QBitArray has none of them. I think i can't do any thing using QBitArray.[/quote]

        I guess it would depend on what you want to achieve. I could imagine a <code>toByteArray()</code> method being useful, but I don't see how a <code>toULong()</code> would help (that would not work for all but very short bit arrays), nor how <code>toString()</code> would be useful. However, the <code>toByteArray()</code> is easy enough to do yourself (just use a QBuffer), so not much is really missing.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          ibingow
          wrote on last edited by
          #4

          but qbitarray does not have any member to convert to another class.
          [quote author="Andre" date="1325072524"]
          [quote author="ibingow" date="1325065025"] std::bitset has to_ulong() and to_string() members, they are very useful. QBitArray has none of them. I think i can't do any thing using QBitArray.[/quote]

          I guess it would depend on what you want to achieve. I could imagine a <code>toByteArray()</code> method being useful, but I don't see how a <code>toULong()</code> would help (that would not work for all but very short bit arrays), nor how <code>toString()</code> would be useful. However, the <code>toByteArray()</code> is easy enough to do yourself (just use a QBuffer), so not much is really missing.

          [/quote]

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

            Again, you are not telling us what you want to achieve, and again, you overlook the option to stream the array to a QByteArray using a QBuffer.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              [quote author="ibingow" date="1325176036"]but qbitarray does not have any member to convert to another class.
              [quote author="Andre" date="1325072524"]

              I guess it would depend on what you want to achieve. I could imagine a...
              [/quote]
              [/quote]

              Seems you missed the highlighted words from Andre....

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

              1 Reply Last reply
              0
              • I Offline
                I Offline
                ibingow
                wrote on last edited by
                #7

                I want to convert a qbitarray to int. I know it's easy to do it myself, an to qbytearray is easy too. But if qbitarray has these methods would be better. std::bitset has to_ulong() because usually shot bitarrys are enough.
                In fact, i am writing a program to parse the swf file. Some flash information like width and height are stored in several bits, not bytes.
                [quote author="Andre" date="1325182451"]Again, you are not telling us what you want to achieve, and again, you overlook the option to stream the array to a QByteArray using a QBuffer.
                [/quote]

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

                  Are you sure you are not looking for QFlags then? You can define their meaning using an enum, so the bits get actual meaning in your application. At least, I find
                  @
                  if (myFlags.testFlag(CoolOption42)) {
                  // some really cool feature
                  }
                  @

                  easier to understand than

                  @
                  if (myBitArray.at(42)) {
                  // some cool feature
                  }
                  @

                  Note that if you want, you can of course just use std::bitset if it suits your needs better. Nothing is stopping you from using std or boost things mixed in with your Qt application.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    [quote author="ibingow" date="1325211343"]
                    In fact, i am writing a program to parse the swf file. Some flash information like width and height are stored in several bits, not bytes.[/quote]

                    So QBitArray is cumbersome to use in the first place here. You would have to construct the bit array from a bunch of bytes into something that doesn't take bytes in its constructor or methods. All that only to split the array afterwards and reconstructing your data. Looks more than awkward to me.

                    I would read the bytes as such and get the bits or bitfields by using masks.

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

                    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