void convertByteArrayToVector(const QByteArray &qba, vector<unsigned char> &vec){ unsigned int size=qba.size(); vec.resize(size, 0); for(unsigned int i=0; i<size; i++) vec[i]=(unsigned char)qba[i];}void convertVectorToByteArray(const vector<unsigned char> &vec, QByteArray &qba){ unsigned int size=vec.size(); qba.resize(size); for(unsigned int i=0; i<size; i++) qba[i]=(unsigned char)vec[i];}
vector<unsigned char> v;v.resize(100);memcpy(&v[0], someArrayOfSize100, 100 * sizeof(unsigned char));
vector<unsigned char> buf;...(char *)(&buf[0])
vector<unsigned char> buf;...unsigned char *p = &*buf.begin();
vector<int> dataVec;int dataArray[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };unsigned dataArraySize = sizeof(dataArray) / sizeof(int);// Method 1: Copy the array to the vector using back_inserter.{ copy(&dataArray[0], &dataArray[dataArraySize], back_inserter(dataVec));}// Method 2: Same as 1 but pre-extend the vector by the size of the array using reserve{ dataVec.reserve(dataVec.size() + dataArraySize); copy(&dataArray[0], &dataArray[dataArraySize], back_inserter(dataVec));}// Method 3: Memcpy{ dataVec.resize(dataVec.size() + dataArraySize); memcpy(&dataVec[dataVec.size() - dataArraySize], &dataArray[0], dataArraySize * sizeof(int));}// Method 4: vector::insert{ dataVec.insert(dataVec.end(), &dataArray[0], &dataArray[dataArraySize]);}// Method 5: vector + vector{ vector<int> dataVec2(&dataArray[0], &dataArray[dataArraySize]); dataVec.insert(dataVec.end(), dataVec2.begin(), dataVec2.end());}
C++ (Qt)dataVec.assign(dataArray, dataArray+dataArraySize);
C++ (Qt)std::vector<char> convert(const QByteArray &b){ return std::vector<char>(b.begin(), b.end());} QByteArray convert(const std::vector<char>& v){ return QByteArray(v.data(), v.size());}
std::vector<char> convert(const QByteArray &b){ return std::vector<char>(b.begin(), b.end());}
C++ (Qt)std::vector<char> convert(const QByteArray &b){ std::vector<char> tmp(b.begin(), b.end()); return tmp;}
C++ (Qt)return std::vector<char>(b.begin(), b.end());
C++ (Qt) std::vector<char> tmp(b.begin(), b.end()); return tmp;
C++ (Qt)std::vector<char> tmp(b.begin(), b.end()); return std::move(tmp);
C++ (Qt)return vector(...)
C++ (Qt)vector tmp;return tmp;