Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] my code make my memory increasing
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] my code make my memory increasing

Scheduled Pinned Locked Moved Mobile and Embedded
qt5.4widgetandroid
5 Posts 4 Posters 1.8k Views 2 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.
  • M Offline
    M Offline
    mkdh
    wrote on last edited by mkdh
    #1

    How to correct my code?

       void diaOpenFileByListView::BindLV(){
       int curRow=-1;
       if(model!=0 && ui->lvwFile->currentIndex().row()>0){
            curRow= ui->lvwFile->currentIndex().row();
        }
        init_styleditemdelegate_cell *listdelegate;
        model = new QStandardItemModel(this);
        ui->lvwFile->setModel(model);
        listdelegate = new init_styleditemdelegate_cell();
        ui->lvwFile->setItemDelegate(listdelegate);
        QDir dir=QDir::rootPath();
        QString myPath;
        myPath=gData->strFileFolder;
        dir.cd(myPath);
        ui->lblPath->setText(dir.absolutePath());
        dir.setNameFilters(QStringList()<<"*.qqq");
        QStringList fileList = dir.entryList();
        QStandardItem *item ;//= new QStandardItem();
        for (int i=0; i<fileList.count(); i++)
        {
            item = new QStandardItem();
            QString tmpFilePaht=dir.absolutePath()+"/"+fileList[i];
            QIcon icon=GetListIcon(tmpFilePaht);
            item->setData(icon,init_styleditemdelegate_cell::IconRole);
            item->setData(tmpFilePaht,init_styleditemdelegate_cell::headerTextRole);
            item->setData(fileList[i],init_styleditemdelegate_cell::subHeaderTextrole);
            item->setEditable(false);
            model->appendRow(item);
        }
       if(model->rowCount()>0){
            if(curRow>-1){
                ui->lvwFile->setCurrentIndex(model->indexFromItem(model->item(curRow,0)));
            }else{
                ui->lvwFile->setCurrentIndex(model->indexFromItem(model->item(0,0)));
            }
        }
        ShowIni();
        }
    
    M 1 Reply Last reply
    0
    • M mkdh

      How to correct my code?

         void diaOpenFileByListView::BindLV(){
         int curRow=-1;
         if(model!=0 && ui->lvwFile->currentIndex().row()>0){
              curRow= ui->lvwFile->currentIndex().row();
          }
          init_styleditemdelegate_cell *listdelegate;
          model = new QStandardItemModel(this);
          ui->lvwFile->setModel(model);
          listdelegate = new init_styleditemdelegate_cell();
          ui->lvwFile->setItemDelegate(listdelegate);
          QDir dir=QDir::rootPath();
          QString myPath;
          myPath=gData->strFileFolder;
          dir.cd(myPath);
          ui->lblPath->setText(dir.absolutePath());
          dir.setNameFilters(QStringList()<<"*.qqq");
          QStringList fileList = dir.entryList();
          QStandardItem *item ;//= new QStandardItem();
          for (int i=0; i<fileList.count(); i++)
          {
              item = new QStandardItem();
              QString tmpFilePaht=dir.absolutePath()+"/"+fileList[i];
              QIcon icon=GetListIcon(tmpFilePaht);
              item->setData(icon,init_styleditemdelegate_cell::IconRole);
              item->setData(tmpFilePaht,init_styleditemdelegate_cell::headerTextRole);
              item->setData(fileList[i],init_styleditemdelegate_cell::subHeaderTextrole);
              item->setEditable(false);
              model->appendRow(item);
          }
         if(model->rowCount()>0){
              if(curRow>-1){
                  ui->lvwFile->setCurrentIndex(model->indexFromItem(model->item(curRow,0)));
              }else{
                  ui->lvwFile->setCurrentIndex(model->indexFromItem(model->item(0,0)));
              }
          }
          ShowIni();
          }
      
      M Offline
      M Offline
      mkdh
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • H Offline
        H Offline
        Huulivoide
        wrote on last edited by
        #3

        The only leak I can find is caused by ui->lvwFile->setModel(model). setModel(model) does not free the old model, instead you need to delete it manually. Your coding style could use some fine tuning init_styleditemdelegate_cell is absolutely horrible class name, and you could add a few newlines here and there to group logical pieces together.

        1 Reply Last reply
        1
        • Q Offline
          Q Offline
          qtwithanzo
          wrote on last edited by
          #4

          @Huulivoide said in [SOLVED] my code make my memory increasing:

          setModel

          How can i delete the model manually in the code? Please guide.
          is there any function which I can use to delete it.
          I found model->deleteLater(); but not sure if this is the correct way to delete the model object manually.

          SGaistS 1 Reply Last reply
          0
          • Q qtwithanzo

            @Huulivoide said in [SOLVED] my code make my memory increasing:

            setModel

            How can i delete the model manually in the code? Please guide.
            is there any function which I can use to delete it.
            I found model->deleteLater(); but not sure if this is the correct way to delete the model object manually.

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @qtwithanzo hi,

            If the model might still be connected elsewhere then yes it's the correct way. Otherwise use the standard C++ delete.

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

            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