The QOpenGLWidget and QLabel updates frequently, resulting in memory leaks
Unsolved
General and Desktop
-
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!
-
@MissingDream Please properly format your code with the code tags ('</>' button) so we can read it.