October 22, 2010

phamtv phamtv
Lab Rat
111 posts

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

 

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!

8 replies

October 22, 2010

Volker Volker
Mad Scientist
5250 posts

  1. QByteArray other("white");
  2. other = ba;

October 22, 2010

Denis Kormalev Denis Kormalev
Area 51 Engineer
1652 posts

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.

October 22, 2010

phamtv phamtv
Lab Rat
111 posts

sorry…

October 22, 2010

phamtv phamtv
Lab Rat
111 posts

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?

October 22, 2010

Volker Volker
Mad Scientist
5250 posts

  1. bb = ba.right(4);

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

October 22, 2010

Tobias Hunger Tobias Hunger
Mad Scientist
1998 posts

Denis: I merged the topics.

October 22, 2010

Andre Andre
Mad Scientist
4667 posts

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.

 Signature 

Nokia Certified Qt Specialist.
Interested in Qt consultancy and job opportunities.

October 22, 2010

phamtv phamtv
Lab Rat
111 posts

thank you all!

 
  ‹‹ little problem with compiling Qt4 app (Ambigious symbol)      Determine if user has administrator rights (windows) ››

You must log in to post a reply. Not a member yet? Register here!