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 issue
Qt 6.11 is out! See what's new in the release blog

Memory leak issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 3 Posters 717 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.
  • Venkatesh VV Offline
    Venkatesh VV Offline
    Venkatesh V
    wrote on last edited by
    #1

    Hi all,

    I'm facing some memory leak issue, i have a tabwidget, there are 4 tabs each tab contains video player(QLabel) and i am fetching video in a different thread and emitting a pixmap from there. once the signal emitted from the thread, setting that pixmap to the active tab video player. the problem is if i run the application memory keep on increases and once and once system disc will be full application gets crashed. please help me with appropriate solution.

    please refer the code bellow:

    //tab widget

    void ServerSetupWidget::SLT_RecieveImage(QPixmap *img)
    {
    if(m_Image!=NULL){
    delete m_Image;
    }
    m_Image = img;
    QRect rec = QApplication::desktop()->screenGeometry();
    int height = rec.height();
    int width = rec.width();

    if(m_stop||m_pause ){
    
    	if(m_stop){
    	 m_VideoPlayer->setPixmap(QPixmap(":/Images/radioBack.jpg").scaled(width/2,height/2));
    	}
        return;
    }
    
    if(!m_Image->isNull() ){
    	//qDebug()<<Q_FUNC_INFO<<"In========"<<endl;
    
        if(m_play && m_isVideoSelected){
        m_VideoPlayer->setPixmap(m_Image->scaled(width/2,height/2));
        }
    }else{
    
    }
    this->update();
    

    }

    //Imageprovider

    void FrameProvider::processFrames()
    {
    VideoCapture cap(m_VideoPath);

    if(!cap.isOpened()){
    cout << "Error opening video stream or file" << endl;
    return ;
    }

    while(1)
    {
    Mat frame;
    cap >> frame;

    QPixmap *Pixmap = new QPixmap(QPixmap::fromImage(QImage((unsigned char*) frame.data, frame.cols, frame.rows, QImage::Format_RGB888)));
     emit SGL_transferPix(Pixmap);
     this->msleep(15);
    

    }

    cap.release();

    destroyAllWindows();
    }

    JKSHJ 1 Reply Last reply
    1
    • Venkatesh VV Venkatesh V

      Hi all,

      I'm facing some memory leak issue, i have a tabwidget, there are 4 tabs each tab contains video player(QLabel) and i am fetching video in a different thread and emitting a pixmap from there. once the signal emitted from the thread, setting that pixmap to the active tab video player. the problem is if i run the application memory keep on increases and once and once system disc will be full application gets crashed. please help me with appropriate solution.

      please refer the code bellow:

      //tab widget

      void ServerSetupWidget::SLT_RecieveImage(QPixmap *img)
      {
      if(m_Image!=NULL){
      delete m_Image;
      }
      m_Image = img;
      QRect rec = QApplication::desktop()->screenGeometry();
      int height = rec.height();
      int width = rec.width();

      if(m_stop||m_pause ){
      
      	if(m_stop){
      	 m_VideoPlayer->setPixmap(QPixmap(":/Images/radioBack.jpg").scaled(width/2,height/2));
      	}
          return;
      }
      
      if(!m_Image->isNull() ){
      	//qDebug()<<Q_FUNC_INFO<<"In========"<<endl;
      
          if(m_play && m_isVideoSelected){
          m_VideoPlayer->setPixmap(m_Image->scaled(width/2,height/2));
          }
      }else{
      
      }
      this->update();
      

      }

      //Imageprovider

      void FrameProvider::processFrames()
      {
      VideoCapture cap(m_VideoPath);

      if(!cap.isOpened()){
      cout << "Error opening video stream or file" << endl;
      return ;
      }

      while(1)
      {
      Mat frame;
      cap >> frame;

      QPixmap *Pixmap = new QPixmap(QPixmap::fromImage(QImage((unsigned char*) frame.data, frame.cols, frame.rows, QImage::Format_RGB888)));
       emit SGL_transferPix(Pixmap);
       this->msleep(15);
      

      }

      cap.release();

      destroyAllWindows();
      }

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Venkatesh-V QPixmap must only be created or used in the GUI thread (that means the thread which created QApplication). You must not use QPixmap in other threads.

      However, you can use QImage in other threads.

      Also, QPixmap is implicitly shared. Don't use new, just create a QPixmap on the stack and pass by-value or by-const-reference.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved