Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to convert QVector<double> to QBytearray then display it via QPixmap
Look_Im_Your_Root last edited by
0 down vote favorite
I have big problem with load and display data. I will load data from .csv file to QVector than convert it to QBytearray and display it via QPixmap.
Bellow I will show you a fiew steps.
- Load data from .csv to QVector
- Convert QVector to QBytearray.
QByteArray InfraredCamera::retFrameBArray(const int* frameNumber)
Frame temp = Pictures[frameNumber];
QVector<double> vec = temp.retVecFrameValue();
QByteArray arr = QByteArray::fromRawData( reinterpret_cast<const char*>(vec),(vec->size())*(sizeof(double)));
for(int i = 0; i< vec->size(); i++) arr.append(reinterpret_cast<const char*>(temp.retFrameValue(&i)),sizeof(double)); return arr;
Than I will display it via QPixmap
int x = 3; //Chose numer of frame to display
QByteArray arr = test->Termo.retFrameBArray(&x);
Then my program crashes.... What should I do with it?
Bonus question: Would have been nice if I could show some of these images as a movie... Anyone know how you can do it?
Hi and welcome to devnet,
From a quick look at your code arr is pointing to an invalid position in memory.
QByteArray::fromRawData explicitly state that there's no copy involved so you have to ensure that the underlying data lives at least as long as the QByteArray which is not the case in your code since temp gets destroyed at the end of retFrameBArray.
On a side note, why are you using a pointer from frameNumber ? Same goes for vec, why a pointer to a QVector ? And why to you need vec since you are only using it to get its size ?