Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: save QPixmap to std::vector<unsigned char> - or convert QByteArray to std::vector<unsigned char>

Tags:

c++

qt

I wanted to convert a QPixmap to std::vector . For now I am doing the following

     QPixmap pixmap;
     QByteArray bytes;
     QBuffer buffer(&bytes);
     buffer.open(QIODevice::WriteOnly);
     pixmap.save(&buffer, "JPG");

However I donot know how to convert QbyteArray to std::vector<unsigned char>

any suggestions ?

like image 977
MistyD Avatar asked Nov 01 '22 09:11

MistyD


1 Answers

Just for the record, as user @Lol4t0 didn't do it:

 std::vector<unsigned char> c(bytes.constData(), bytes.constData() + bytes.size());
like image 68
kikeenrique Avatar answered Nov 04 '22 12:11

kikeenrique