S
S
Sergey Kravchenko2015-08-31 11:47:27
Programming
Sergey Kravchenko, 2015-08-31 11:47:27

How to parse QByteArray to QVector?

Good day!
We have a QByteArray that contains
"2700\n1455\n762\1834\n" It is
necessary to make a QVector d array out of it, such that
d[0] = 2700, d[1]=1455, d[2] = 762, d[ 3] 1834.
Please tell me how can this be done?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2015-08-31
@Paladin1032

First, use the .split() method to split it at the \n character. Get list from arrays.
Then, use the to_long method to convert each array into numbers and write it to the array.

V
Vladimir Martyanov, 2015-08-31
@vilgeforce

Split the QByteArray by the separator '\n', each resulting element needs to be run through the analog of atoi, which I don't remember in Qt. It's not clear what the problem is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question