Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert QVector<double> to QBytearray then display it via QPixmap

How to convert QVector<double> to QBytearray then display it via QPixmap

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Look_Im_Your_Root
    wrote on last edited by
    #1

    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.

    1. Load data from .csv to QVector
    2. 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;
    

    }
    @

    1. Than I will display it via QPixmap

      @
      int x = 3; //Chose numer of frame to display
      QByteArray arr = test->Termo.retFrameBArray(&x);
      QPixmap pic;
      pic.loadFromData(arr);@

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved