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. QTABLEWIDGET CONSUMES LOTS OF MEMORY
Forum Updated to NodeBB v4.3 + New Features

QTABLEWIDGET CONSUMES LOTS OF MEMORY

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 629 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.
  • C Offline
    C Offline
    canrollas
    wrote on last edited by
    #1

    Hi this is my table widget code which get signal from serial device every 0.5 milliseconds. But It consumes huge memory . For example it starts with 3mb ram ; after every 1 seconds it increases 3mb more. When I stop displaying the table it does not consume memory. What should I do about it? THX.

    void MainWindow::getTavbleData(QString data, QString data2, QString data3, QString data4, QString data5, QString data6, QString data7, QString data8, QString data9, QString data10, QString data11, QString data12, QString data13)
    {
    
        if(rowCheck>100){
            ui->tableWidget_2->clear();
    
            rowCheck = 0;
        }
        QVector<QTableWidgetItem> *widgetVector = new QVector<QTableWidgetItem>;
    
        rowCheck = rowCheck + 1;
        ui->tableWidget_2->setRowCount(rowCheck);
        QTableWidgetItem *table1 = new QTableWidgetItem(data);
        QTableWidgetItem *table2 = new QTableWidgetItem(data2);
        QTableWidgetItem *table3 = new QTableWidgetItem(data3);
        QTableWidgetItem *table4 = new QTableWidgetItem(data4);
        QTableWidgetItem *table5 = new QTableWidgetItem(data5);
        QTableWidgetItem *table6 = new QTableWidgetItem(data6);
        QTableWidgetItem *table7 = new QTableWidgetItem(data7);
        QTableWidgetItem *table8 = new QTableWidgetItem(data8);
        QTableWidgetItem *table9 = new QTableWidgetItem(data9);
        QTableWidgetItem *table10 = new QTableWidgetItem(data10);
        QTableWidgetItem *table11 = new QTableWidgetItem(data11);
        QTableWidgetItem *table12 = new QTableWidgetItem(data12);
        QTableWidgetItem *table13 = new QTableWidgetItem(data13);
        ui->tableWidget_2->setItem(rowCheck-1,0,table1 );
        ui->tableWidget_2->setItem(rowCheck-1,1,table2 );
        ui->tableWidget_2->setItem(rowCheck-1,2,table3 );
        ui->tableWidget_2->setItem(rowCheck-1,3,table4 );
        ui->tableWidget_2->setItem(rowCheck-1,4,table5 );
        ui->tableWidget_2->setItem(rowCheck-1,5,table6 );
        ui->tableWidget_2->setItem(rowCheck-1,6,table7 );
        ui->tableWidget_2->setItem(rowCheck-1,7,table8 );
        ui->tableWidget_2->setItem(rowCheck-1,8,table9 );
        ui->tableWidget_2->setItem(rowCheck-1,9,table10 );
        ui->tableWidget_2->setItem(rowCheck-1,10,table11 );
        ui->tableWidget_2->setItem(rowCheck-1,11,table12 );
        ui->tableWidget_2->setItem(rowCheck-1,12,table13 );
    
    
    
    
        if(rowCheck%10==0){
            ui->tableWidget_2->scrollToBottom();
        }
        widgetVector->clear();
        delete widgetVector;
    
    
    
    
    
    
    
    }
    
    
    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      What is the amount of data that you put into your table ?
      What about that vector that you don't use ?

      On a side note, please avoid writing titles all in upper case. In written language it's considered shouting and rude.

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

      C 1 Reply Last reply
      1
      • C canrollas

        Hi this is my table widget code which get signal from serial device every 0.5 milliseconds. But It consumes huge memory . For example it starts with 3mb ram ; after every 1 seconds it increases 3mb more. When I stop displaying the table it does not consume memory. What should I do about it? THX.

        void MainWindow::getTavbleData(QString data, QString data2, QString data3, QString data4, QString data5, QString data6, QString data7, QString data8, QString data9, QString data10, QString data11, QString data12, QString data13)
        {
        
            if(rowCheck>100){
                ui->tableWidget_2->clear();
        
                rowCheck = 0;
            }
            QVector<QTableWidgetItem> *widgetVector = new QVector<QTableWidgetItem>;
        
            rowCheck = rowCheck + 1;
            ui->tableWidget_2->setRowCount(rowCheck);
            QTableWidgetItem *table1 = new QTableWidgetItem(data);
            QTableWidgetItem *table2 = new QTableWidgetItem(data2);
            QTableWidgetItem *table3 = new QTableWidgetItem(data3);
            QTableWidgetItem *table4 = new QTableWidgetItem(data4);
            QTableWidgetItem *table5 = new QTableWidgetItem(data5);
            QTableWidgetItem *table6 = new QTableWidgetItem(data6);
            QTableWidgetItem *table7 = new QTableWidgetItem(data7);
            QTableWidgetItem *table8 = new QTableWidgetItem(data8);
            QTableWidgetItem *table9 = new QTableWidgetItem(data9);
            QTableWidgetItem *table10 = new QTableWidgetItem(data10);
            QTableWidgetItem *table11 = new QTableWidgetItem(data11);
            QTableWidgetItem *table12 = new QTableWidgetItem(data12);
            QTableWidgetItem *table13 = new QTableWidgetItem(data13);
            ui->tableWidget_2->setItem(rowCheck-1,0,table1 );
            ui->tableWidget_2->setItem(rowCheck-1,1,table2 );
            ui->tableWidget_2->setItem(rowCheck-1,2,table3 );
            ui->tableWidget_2->setItem(rowCheck-1,3,table4 );
            ui->tableWidget_2->setItem(rowCheck-1,4,table5 );
            ui->tableWidget_2->setItem(rowCheck-1,5,table6 );
            ui->tableWidget_2->setItem(rowCheck-1,6,table7 );
            ui->tableWidget_2->setItem(rowCheck-1,7,table8 );
            ui->tableWidget_2->setItem(rowCheck-1,8,table9 );
            ui->tableWidget_2->setItem(rowCheck-1,9,table10 );
            ui->tableWidget_2->setItem(rowCheck-1,10,table11 );
            ui->tableWidget_2->setItem(rowCheck-1,11,table12 );
            ui->tableWidget_2->setItem(rowCheck-1,12,table13 );
        
        
        
        
            if(rowCheck%10==0){
                ui->tableWidget_2->scrollToBottom();
            }
            widgetVector->clear();
            delete widgetVector;
        
        
        
        
        
        
        
        }
        
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @canrollas
        Also:

        • Does the extra memory used settle down after a while, or are you claiming it keeps increasing forever?
        • Can we assume you do allow the main Qt event loop to run in between calls to this function?

        And as @SGaist said, are you hiding any code on the widgetVector?

        C 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          What is the amount of data that you put into your table ?
          What about that vector that you don't use ?

          On a side note, please avoid writing titles all in upper case. In written language it's considered shouting and rude.

          C Offline
          C Offline
          canrollas
          wrote on last edited by
          #4

          @SGaist It comes from serial device every 0.5 ms and basically It is parsed 36 digit hexadecimal message string . it produces 13 variable. The vector part was my fault which forget about deleting. It does not change the memory leak. Sorry about the uppercase Im fixing it.

          Christian EhrlicherC 1 Reply Last reply
          0
          • JonBJ JonB

            @canrollas
            Also:

            • Does the extra memory used settle down after a while, or are you claiming it keeps increasing forever?
            • Can we assume you do allow the main Qt event loop to run in between calls to this function?

            And as @SGaist said, are you hiding any code on the widgetVector?

            C Offline
            C Offline
            canrollas
            wrote on last edited by
            #5

            @JonB Thanks, I have answered the JonB you can take a look .

            JonBJ 1 Reply Last reply
            0
            • C canrollas

              @JonB Thanks, I have answered the JonB you can take a look .

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @canrollas I do not see a response to either of my questions.

              1 Reply Last reply
              0
              • C canrollas

                @SGaist It comes from serial device every 0.5 ms and basically It is parsed 36 digit hexadecimal message string . it produces 13 variable. The vector part was my fault which forget about deleting. It does not change the memory leak. Sorry about the uppercase Im fixing it.

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

                @canrollas said in QTABLEWIDGET CONSUMES LOTS OF MEMORY:

                It comes from serial device every 0.5 ms and basically It is parsed 36 digit hexadecimal message string . it produces 13 variable.

                Then use a proper table model and not a convenience QTableWidget. Also 0.5ms can not see anyone so I would suggest to strip down the number of rows.

                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