Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    5
    9
    6370
    Loading More Posts
    • 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
      phamtv last edited by

      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 Reply Quote 0
      • G
        goetz last edited by

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

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

        1 Reply Last reply Reply Quote 0
        • D
          DenisKormalev last edited by

          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 Reply Quote 0
          • P
            phamtv last edited by

            sorry...

            1 Reply Last reply Reply Quote 0
            • P
              phamtv last edited by

              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 Reply Quote 0
              • G
                goetz last edited by

                @
                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 Reply Quote 0
                • T
                  tobias.hunger last edited by

                  Denis: I merged the topics.

                  1 Reply Last reply Reply Quote 0
                  • A
                    andre last edited by

                    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 Reply Quote 0
                    • P
                      phamtv last edited by

                      thank you all!

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post