Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying a std::vector to a qvector

Tags:

c++

qt

I tried copy content of one vector to a QVector using the following

std::copy(source.begin(), source.end(), dest.begin());

However the destination QVector still is empty.

Any suggestions ?

like image 258
Rajeshwar Avatar asked Aug 08 '13 15:08

Rajeshwar


2 Answers

Look at:

std::vector<T> QVector::toStdVector () const

QVector<T> QVector::fromStdVector ( const std::vector<T> & vector ) [static]

From docs

like image 120
trompa Avatar answered Oct 06 '22 00:10

trompa


If you are creating a new QVector with the contents of a std::vector you can use the following code as an example:

   std::vector<T> stdVec;
   QVector<T> qVec = QVector<T>::fromStdVector(stdVec);
like image 42
dunc123 Avatar answered Oct 06 '22 00:10

dunc123