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. The QOpenGLWidget and QLabel updates frequently, resulting in memory leaks
Forum Updated to NodeBB v4.3 + New Features

The QOpenGLWidget and QLabel updates frequently, resulting in memory leaks

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 131 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.
  • M Offline
    M Offline
    MissingDream
    wrote on last edited by MissingDream
    #1

    The code is as follows:

    class PlayerLabelSubtitle2 : public QLabel
    {
    public:
           PlayerLabelSubtitle2(QWidget* pareat, int x, int y, int w, int h) : QLabel(pareat)
    	{
    		x_ = x;
    		y_ = y;
    		width_ = w;
    		height_ = h;
    		move(x, y);
    		resize(w, h);
    	}
    protected:
    	void paintEvent(QPaintEvent *event)
    	{
    		return;
    	}
    private:
    private:
    	int x_;
    	int y_;
    	int width_;
    	int height_;
    };
    
    class XVideoWidget : public QOpenGLWidget, protected QOpenGLFunctions
    {
    	Q_OBJECT
    
    public:
    	XVideoWidget(QWidget* parent = NULL):QOpenGLWidget(parent){}
    	~XVideoWidget()
    	{
    		for (auto label : label_)
                    {
                          delete label;
                    }
                    label_.clear();
    	}
    protected:
    	void initializeGL(){}
    	void paintGL(){}
    	void resizeGL(int width, int height){}
    public:
    	int handle()
    	{
    		update();
    		for (auto& label : label_)
    			label->update();
    		return 0;
    	}
    	
    	void this_run()
    	{
    
    		play_timer_ = new QTimer;
    		play_timer_->setInterval(5);
    		connect(play_timer_, &QTimer::timeout, this, &XVideoWidget::handle);
    		resize(1920, 1079);
    
    		int y = 0;
    		for (int i = 0; i < 3; i++)
    		{
    			PlayerLabelSubtitle2* temp = new PlayerLabelSubtitle2(this, 0, y, 300, 100);
    			temp->show();
    			label_.push_back(temp);
    			y += 200;
    		}
    		play_timer_->start();
    	}
    };
    
    
    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
            XVideoWidget w;
    	w.show();
    	w.this_run();
            return a.exec();
    }
    

    In the code above, memory is always growing, and increasing the timer interval will slow it down . Does anyone know a solution? thanks very much!

    Christian EhrlicherC 1 Reply Last reply
    0
    • M MissingDream

      The code is as follows:

      class PlayerLabelSubtitle2 : public QLabel
      {
      public:
             PlayerLabelSubtitle2(QWidget* pareat, int x, int y, int w, int h) : QLabel(pareat)
      	{
      		x_ = x;
      		y_ = y;
      		width_ = w;
      		height_ = h;
      		move(x, y);
      		resize(w, h);
      	}
      protected:
      	void paintEvent(QPaintEvent *event)
      	{
      		return;
      	}
      private:
      private:
      	int x_;
      	int y_;
      	int width_;
      	int height_;
      };
      
      class XVideoWidget : public QOpenGLWidget, protected QOpenGLFunctions
      {
      	Q_OBJECT
      
      public:
      	XVideoWidget(QWidget* parent = NULL):QOpenGLWidget(parent){}
      	~XVideoWidget()
      	{
      		for (auto label : label_)
                      {
                            delete label;
                      }
                      label_.clear();
      	}
      protected:
      	void initializeGL(){}
      	void paintGL(){}
      	void resizeGL(int width, int height){}
      public:
      	int handle()
      	{
      		update();
      		for (auto& label : label_)
      			label->update();
      		return 0;
      	}
      	
      	void this_run()
      	{
      
      		play_timer_ = new QTimer;
      		play_timer_->setInterval(5);
      		connect(play_timer_, &QTimer::timeout, this, &XVideoWidget::handle);
      		resize(1920, 1079);
      
      		int y = 0;
      		for (int i = 0; i < 3; i++)
      		{
      			PlayerLabelSubtitle2* temp = new PlayerLabelSubtitle2(this, 0, y, 300, 100);
      			temp->show();
      			label_.push_back(temp);
      			y += 200;
      		}
      		play_timer_->start();
      	}
      };
      
      
      int main(int argc, char *argv[])
      {
      	QApplication a(argc, argv);
              XVideoWidget w;
      	w.show();
      	w.this_run();
              return a.exec();
      }
      

      In the code above, memory is always growing, and increasing the timer interval will slow it down . Does anyone know a solution? thanks very much!

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @MissingDream Please properly format your code with the code tags ('</>' button) so we can read it.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      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