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. Memory leak from promoted class of QDoubleSpinBox

Memory leak from promoted class of QDoubleSpinBox

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 299 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by summit
    #1

    I am promoting the QDoubleSpinBox class as i want to catch the mouseDoubleClick Event.

    This is the Promoted class.

    class SumDoubleBox : public QDoubleSpinBox
    {
        Q_OBJECT
    public:
    
        explicit SumDoubleBox(QWidget* parent = nullptr);   
        void stepBy(int steps) override;
    protected:
        virtual void focusInEvent(QFocusEvent *e) override;         
    public slots:       
        void setZero();
    
    signals:
        int signalUndoRedo();
    
    private:
        double m_defaultStep = 1.0;
    };
    
    SumDoubleBox::SumDoubleBox(QWidget* parent) : QDoubleSpinBox(parent)
    {
        SumLineEdit* lineEdit = new SumLineEdit(this);
        setLineEdit(lineEdit);
        setMinimum(0.0);
        setMaximum(99999.0);
    }
    

    Since i am creating a pointer in the Constructor of the SumDoubleBox Class.

    SumLineEdit* lineEdit = new SumLineEdit(this);
    ``
    
    

    Do i need to Explicitly delete this in the Destructor ?

    Defination of SumLineEdit Class.
    
    
    class SumLineEdit : public QLineEdit
    {
        Q_OBJECT
    
    public:
        explicit SumLineEdit(QWidget* parent = nullptr) {   };
    protected:
        void mouseDoubleClickEvent(QMouseEvent* event) override;
    };
    
    
    void SumLineEdit::mouseDoubleClickEvent(QMouseEvent* event)
    {
        if (event->button() == Qt::LeftButton)
        {
            selectAll();
            event->accept();
            return;
        }
        QLineEdit::mouseDoubleClickEvent(event);
    }
    
    JonBJ 1 Reply Last reply
    0
    • S summit

      I am promoting the QDoubleSpinBox class as i want to catch the mouseDoubleClick Event.

      This is the Promoted class.

      class SumDoubleBox : public QDoubleSpinBox
      {
          Q_OBJECT
      public:
      
          explicit SumDoubleBox(QWidget* parent = nullptr);   
          void stepBy(int steps) override;
      protected:
          virtual void focusInEvent(QFocusEvent *e) override;         
      public slots:       
          void setZero();
      
      signals:
          int signalUndoRedo();
      
      private:
          double m_defaultStep = 1.0;
      };
      
      SumDoubleBox::SumDoubleBox(QWidget* parent) : QDoubleSpinBox(parent)
      {
          SumLineEdit* lineEdit = new SumLineEdit(this);
          setLineEdit(lineEdit);
          setMinimum(0.0);
          setMaximum(99999.0);
      }
      

      Since i am creating a pointer in the Constructor of the SumDoubleBox Class.

      SumLineEdit* lineEdit = new SumLineEdit(this);
      ``
      
      

      Do i need to Explicitly delete this in the Destructor ?

      Defination of SumLineEdit Class.
      
      
      class SumLineEdit : public QLineEdit
      {
          Q_OBJECT
      
      public:
          explicit SumLineEdit(QWidget* parent = nullptr) {   };
      protected:
          void mouseDoubleClickEvent(QMouseEvent* event) override;
      };
      
      
      void SumLineEdit::mouseDoubleClickEvent(QMouseEvent* event)
      {
          if (event->button() == Qt::LeftButton)
          {
              selectAll();
              event->accept();
              return;
          }
          QLineEdit::mouseDoubleClickEvent(event);
      }
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @summit said in Memory leak from promoted class of QDoubleSpinBox:

      Do i need to Explicitly delete this in the Destructor ?

      No, because new SumLineEdit(this) https://doc.qt.io/qt-6/qabstractspinbox.html#setLineEdit

      QAbstractSpinBox takes ownership of the new lineEdit

      S 1 Reply Last reply
      3
      • JonBJ JonB

        @summit said in Memory leak from promoted class of QDoubleSpinBox:

        Do i need to Explicitly delete this in the Destructor ?

        No, because new SumLineEdit(this) https://doc.qt.io/qt-6/qabstractspinbox.html#setLineEdit

        QAbstractSpinBox takes ownership of the new lineEdit

        S Offline
        S Offline
        summit
        wrote on last edited by summit
        #3

        @JonB Thank you very much for the answer.

        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