Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. class member is changed by who????
Forum Updated to NodeBB v4.3 + New Features

class member is changed by who????

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 279 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.
  • Q Offline
    Q Offline
    QtTester
    wrote on last edited by
    #1

    hey guys:
    I use a qquickwidget to show qml file. and I want to scale and center the image with QQuickPaintedItem, but I found the member will be changed,do not know why:

    class CamPipItem : public QQuickPaintedItem
    {
        Q_OBJECT
    .....
    private:
        const QRectF m_finalRect{1,1,150,150};
        QImage m_bgImg,m_dispImg;
        qreal m_finalW,m_finalH;
        const QSize m_pipRect{152,152};
    };
    
    
    void CamPipItem::paint(QPainter *painter)
    {
        auto *img = &m_dispImg;
    
        qDebug("w:%d,h:%d",width(),height());
    
        // m_pipRect is changed to random number
        painter->drawRect(0,0,m_pipRect.width()-1,m_pipRect.height()-1);
        painter->drawImage(m_finalRect.x(),m_finalRect.y(),*img);
    }
    
    

    m_pipRect is a const member, but it's changed:

    微信截图_20241112145452.png
    thanks for the attention.

    jsulmJ 1 Reply Last reply
    0
    • Q QtTester

      hey guys:
      I use a qquickwidget to show qml file. and I want to scale and center the image with QQuickPaintedItem, but I found the member will be changed,do not know why:

      class CamPipItem : public QQuickPaintedItem
      {
          Q_OBJECT
      .....
      private:
          const QRectF m_finalRect{1,1,150,150};
          QImage m_bgImg,m_dispImg;
          qreal m_finalW,m_finalH;
          const QSize m_pipRect{152,152};
      };
      
      
      void CamPipItem::paint(QPainter *painter)
      {
          auto *img = &m_dispImg;
      
          qDebug("w:%d,h:%d",width(),height());
      
          // m_pipRect is changed to random number
          painter->drawRect(0,0,m_pipRect.width()-1,m_pipRect.height()-1);
          painter->drawImage(m_finalRect.x(),m_finalRect.y(),*img);
      }
      
      

      m_pipRect is a const member, but it's changed:

      微信截图_20241112145452.png
      thanks for the attention.

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

      @QtTester Print out the m_pipRect value using qDebug() - could be that this is a debugger issue.

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

      Q 1 Reply Last reply
      0
      • jsulmJ jsulm

        @QtTester Print out the m_pipRect value using qDebug() - could be that this is a debugger issue.

        Q Offline
        Q Offline
        QtTester
        wrote on last edited by
        #3

        @jsulm
        it is the same result:
        微信截图_20241112145452.png

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

          Hi,

          What if you use standard initialization rather than initializer list at creation time ?

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

          Q 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            What if you use standard initialization rather than initializer list at creation time ?

            Q Offline
            Q Offline
            QtTester
            wrote on last edited by
            #5

            @SGaist
            I restart the computer, delete all obj file and rebuild , now it runs fine.
            stupid microsoft -_-

            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