PDA

View Full Version : command related to qt version 5.1.1



ntl
29th January 2015, 13:11
what is the command used for storing an array of values in an vector in qt 5.1.1?

anda_skoa
29th January 2015, 13:28
Both the array and a suitably sized vector can be accessed by numerical index.

Alternatively you can get the data from the suitably sized array and perform a memcpy()

Cheers,
_

ntl
30th January 2015, 08:28
we found that memcpy() is used for storing strings. can this command also be used for storing the integer values in the vector?suggest some other related commands. Thank you.

yeye_olive
30th January 2015, 10:27
we found that memcpy() is used for storing strings. can this command also be used for storing the integer values in the vector?suggest some other related commands. Thank you.
memcpy() works on any POD, including integers. If I were you i would use std::copy, which is always correct and probably optimized to do memcpy where appropriate:


QVector<int> intVector;
int intArray[COUNT];
/* ... */
/* Here I assume that intVector is large enough */
std::copy(intArray, intArray + COUNT, intVector.begin());