Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
Visit the Qt Academy at https://academy.qt.io/catalog
@Christian-Ehrlicher 's solution is the way to go. I got complicated on mine:
std::vector<unsigned char> source = {'a'+0,'a'+1,'a'+2,'a'+3,'a'+4,'a'+5,'a'+6,'a'+7,'a'+8,'a'+9};
QByteArray output; // empty byte array
for(auto val: source){
output.push_back(val);
// or use something from algorithm
QByteArray output2;
std::copy(source.begin(), source.end(), std::back_inserter(output2));
qInfo() << output;
qInfo() << output2;
That is how I ended up doing it:
QByteArray encodeInput = "Hello world";
std::vector<unsigned char> encodeResultVector;
encodeResultVector.reserve(encodeInput.size());
for(int i = 0; i < encodeInput.size(); ++i)
encodeResultVector.push_back(static_cast<unsigned char>(encodeInput.at(i)));
std::string encodeReslutStdString = EncodeBase58(encodeResultVector);
QByteArray encodedArray(encodeReslutStdString.c_str(), encodeReslutStdString.length());
qDebug() << "encode input :" << encodeInput;
qDebug() << "encoded array :" << encodedArray;
QByteArray decodedArray;
std::vector<unsigned char> vchRet;
bool ret = DecodeBase58(encodedArray.constData(), vchRet);
decodedArray.reserve(vchRet.size());
for(size_t i = 0; i < vchRet.size(); ++i)
decodedArray.append(vchRet.at(i));
qDebug() << "decoded array :" << decodedArray;
encode input : "Hello world"
encoded array : "JxF12TrwXzT5jvT"
decoded array : "Hello world"
Can I ask why qt did not insert the static Function fromStdVectorUint8t to QByteArray?
you can make QString from 4 Basic_string variants char, char16_t, char32_t and wchar_t
why not bytearry from Std::vector<uint8_t> ?
@QtCoder87 said in How to convert (const std::vector<unsigned char>& vchIn) to QByteArray?:
why not bytearry from Std::vector<uint8_t> ?
Mainly because there was little demand for it.
It is very easy to and cheap to reinterpret a uint8_t
array as a char
array, so QByteArray::fromStdUInt8Vector(const std::vector<uint_8> &vector)
wouldn't add much value. Just use QByteArray(const char *data, int size)
.
Anyway, future code should not use uint8_t
OR char
. Instead, we should move towards std::byte
.