Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Draw buffer
Qt 6.11 is out! See what's new in the release blog

Draw buffer

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 2 Posters 2.7k Views
  • 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.
  • hjparkH Offline
    hjparkH Offline
    hjpark
    wrote on last edited by
    #1

    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.

                                                                                                                              ^
    
    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        And why m_pCameraBuf[DATA_DEPTH] and not just m_pCameraBuf?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        hjparkH 1 Reply Last reply
        0
        • jsulmJ jsulm

          And why m_pCameraBuf[DATA_DEPTH] and not just m_pCameraBuf?

          hjparkH Offline
          hjparkH Offline
          hjpark
          wrote on last edited by
          #4

          @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..

          jsulmJ 1 Reply Last reply
          0
          • hjparkH hjpark

            @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..

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            hjparkH 1 Reply Last reply
            0
            • jsulmJ jsulm

              @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?

              hjparkH Offline
              hjparkH Offline
              hjpark
              wrote on last edited by
              #6

              @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);

              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