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. [Merged] How to instantiate another QByteArray from and existing array?

[Merged] How to instantiate another QByteArray from and existing array?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 6.7k 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.
  • P Offline
    P Offline
    phamtv
    wrote on last edited by
    #1

    For instance:
    QByteArray ba(" lots\t of\nwhitespace\r\n ");

    I want to most effective what to instantiate and resize another QByteArray with value ¨white¨ from ba.

    Thanks!

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

      @
      QByteArray other("white");
      other = ba;
      @

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        Hm. This category is not for dev questions. It is only for questions about using Qt in education methods (i.e. in universities or via seminars). Your first question was merged with another one and stayed in Desktop category because Desktop category fits your question, not this one.

        2Someone who has rights in this category: merge it with one in Destop, please.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          phamtv
          wrote on last edited by
          #4

          sorry...

          1 Reply Last reply
          0
          • P Offline
            P Offline
            phamtv
            wrote on last edited by
            #5

            For instance,

            I have a QByteArray ba(¨This is a test¨);
            I have another QByteArray bb;

            How can I copy the word ¨test¨ from ba to bb and have it instantiate as well as resize the bb variable?

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

              @
              bb = ba.right(4);
              @

              The size is handled internally. If you really want to, you can call bb.squeeze(), but that's hardly necessary.

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

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tobias.hunger
                wrote on last edited by
                #7

                Denis: I merged the topics.

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

                  Note that the copy in itself is cheap. Only if you start modifying your copy will the actual memory be copied. QByteArray is an implicitly shared class.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    phamtv
                    wrote on last edited by
                    #9

                    thank you all!

                    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