Draw buffer



  • Hi Guys,

    I'm in trouble to draw a buffer on widget.. this is my code

        int imageWidth = IMAGE_WIDTH;
        int imageHeight = IMAGE_HEIGHT;
        int bytesPerPixel = 2; 
        int format = QImage::Format_RGB16; 
        QImage image( m_pCameraBuf[DATA_DEPTH], imageWidth, imageHeight, imageWidth * bytesPerPixel, format);
        painter.drawImage(30,100, image);
    

    unsigned short *m_pCameraBuf[TOTAL]; is defined in the class and I allocated memory with malloc before this code.

    and then I tried to compile it but facing the error below.

    error: no matching function for call to 'QImage::QImage(short unsigned int*&, int&, int&, int, int&)'
    QImage image( m_pCameraBuf[DATA_DEPTH], imageWidth, imageHeight, imageWidth * bytesPerPixel, format);
    ^
    I'm a beginner . sorry but please help me to know what's wrong on my code..
    thanks a lot.

                                                                                                                              ^

  • Moderators

    Your m_pCameraBuf is of type short[], right? It has to be a uchar array. See here http://doc.qt.io/qt-5/qimage.html#QImage-3


  • Moderators

    And why m_pCameraBuf[DATA_DEPTH] and not just m_pCameraBuf?



  • @jsulm
    Thanks a lot for your help..

    An external API " mtfReadFromDevice(m_hnDevice, (unsigned short**)m_pCameraBuf); " requires 2 buffers

    unsigned short *m_pCameraBuf[TOTAL] => #define TOTAL 2

    and, I can't change the code of mtfReadFromDevice becuase it has been provided with lib only

    so, I tried to cast short to uchar like it
    QImage image( (uchar *)m_pCameraBuf[DATA_DEPTH])

    but, facing

    error: invalid user-defined conversion from 'uchar* {aka unsigned char*}' to 'const QString&' [-fpermissive]
    QImage image((uchar*)m_pCameraBuf[DATA_DEPTH]);

                                                      ^
    

    Please help me again.. thanks..


  • Moderators

    @hjpark Please use the same QImage constructor a before:

    QImage image(reinterpret_cast<uchar*>(m_pCameraBuf), imageWidth, imageHeight, imageWidth * bytesPerPixel, format);
    

    And why do you pass m_pCameraBuf[DATA_DEPTH] and not m_pCameraBuf?



  • @jsulm

    hi..

    I tried to compile with QT5.2.1 instaed of 5.7 and no more error with this code.. an it works well.

    QImage image( (uchar*) m_pCameraBuf[DATA_DEPTH], imageWidth, imageHeight, imageWidth * bytesPerPixel, QImage::Format_RGB16, Q_NULLPTR, Q_NULLPTR);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.