Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved we have use qt TableView like sample source. but the memory was leaked.

    QML and Qt Quick
    tableview memory leak resolution with
    2
    6
    1720
    Loading More Posts
    • 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.
    • liuyang
      liuyang last edited by

      we have use qt TableView like sample source. but the memory was leaked.
      please support us to prevent the memory leaks.
      Entry QML:Screen.qml

      c++ sample source:
      1)display
      beginRemoveRows(QModelIndex(), 0, 0);
      for (i = - 1; i >= 0; --i)
      {
      m_inputPointList.removeAt(i);
      }
      endRemoveRows();
      beginInsertRows(QModelIndex(), 0, loopCnt-1);
      for(i = 0 ; i < loopCnt; ++i){
      ......
      m_inputPointList.append(point);
      }
      endInsertRows();
      2) data refresh
      beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
      for (i = m_inputPointList.count() - 1; i >= 0; --i)
      {

              m_inputPointList.removeAt(i);
          }
          endRemoveRows();
          beginInsertRows(QModelIndex(), 0, loopCnt-1);
          for(i = 0 ; i < loopCnt; ++i){
             ......
              m_inputPointList.append(point);
          }
          endInsertRows();
      
      1. nondisplay
        beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
        for (i = m_inputPointList.count() - 1; i >= 0; --i)
        {

             m_inputPointList.removeAt(i);
         }
         endRemoveRows();
        
      C 1 Reply Last reply Reply Quote 0
      • C
        cheezus @liuyang last edited by

        @liuyang Are you aware of how memory leaks are created in JavaScript? It's subtly different than in C++. Think of objects in JavaScript like shared_ptr in C++: as long as you have a reference to the object, it will not be garbage collected.

        liuyang 2 Replies Last reply Reply Quote 0
        • liuyang
          liuyang @cheezus last edited by

          @cheezus we've confirmed that there is not memory leak on c++ side.

          can you tell me how to attach files.
          the sample source is listed folloing.
          please tell me the reason of leak.

          MyTableView.qml
          import QtQuick 2.5
          import QtQuick.Controls 1.4
          import QtQuick.Controls.Styles 1.4
          import ...

          MyItem {
          id: myTableView

          /* テーブルビュー */
          property QtObject tableViewStyle: QtObject {
              //common
              property real opacity: 1.0
              property int fontPixelSize: Style.basicFont.pixelSize
              property int leftMargin: 8
              property int rightMargin: 8
          
              //header
              property int headerBorderWidth: 0
              property int headerInsideBorderWidth: 1
              property color headerInsideBorderColor: Style.basicColorStyle.gray5
              property color headerBgColor: Style.basicColorStyle.darkblue
              property int headerRowHeight: 28
              property color headerFontColor: Style.basicColorStyle.white
          
              //body
              property color bodyBgColor: Style.basicColorStyle.white
              property color bodyBgStripeColor: Style.basicColorStyle.peerblue
              property color bodySelectedBgColor: Style.basicColorStyle.lightblue
              property int bodyRowHeight: 30
              property int bodyBorderWidth: 1
              property color bodyBorderColor: Style.basicColorStyle.gray2
              property color bodySelectedBorderColor: Style.basicColorStyle.blue
              property int bodyInsideBorderWidth: 1
              property color bodyInsideBorderColor: Style.basicColorStyle.gray3
              property color bodyFontColor: Style.basicColorStyle.black
              property color itemBgColor: "transparent"
          
              //drag
              property color dropAreaColor: Style.basicColorStyle.lightblue
              property color dropAreaBorderColor: Style.basicColorStyle.vividblue
              property int dropAreaBorderWidth: 2
          }
          
          property Component customItemDelegate: null
          
          property var displayItem: null
          property bool dragDropEnable: false
          property string dropKey: "dropKey"
          property bool resizeable: false
          property bool verticalScroll: false
          property var expansionTitle: null
          /* 一ページに表示可能の最大行数、verticalScroll=false時無視する */
          property int showRowCount: 10
          property alias currentRow: tableView.currentRow
          readonly property alias rowCount: tableView.rowCount
          property alias onfocus: tableView.focus
          
          /* 上位エレメントへ通知 */
          signal rowMoved(int from, int to);
          signal rowSelected(int rowIndex);
          
          enabled: displayItem === null ? true : displayItem.enabled
          visible: displayItem === null ? true : displayItem.visible
          
          property int resizeColIndex: 0
          
          property real resizeColBasicWidth
          
          signal resizeColumnWidth(real addWidth)
          
          onResizeColumnWidth: {
              if(resizeable === true)
              {
                  if(tableView.isExistColumn(resizeColIndex) === true &&
                          tableView.getColumn(resizeColIndex).width + addWidth > myTableView.resizeColBasicWidth)
                  {
                      tableView.getColumn(resizeColIndex).width += addWidth;
                  }
              }
          }
          
          function addColumn(column) {
              return tableView.addColumn(column);
          }
          
          function insertColumn(index, column) {
              return tableView.insertColumn(index, column);
          }
          
          /* 指定する行をテーブルの先頭に表示する。 */
          function positionTableRowAtTop(row)
          {
              //rowは-1より大きい、かつ、TableViewの行数より小さいの場合は、
              //パラメータrowで指定したテーブル行をmyTableViewの先頭に表示する。
              if(row > -1 && row < tableView.rowCount)
              {
                  tableView.positionViewAtRow(row,ListView.Beginning);
              }
          }
          
          C 1 Reply Last reply Reply Quote 0
          • liuyang
            liuyang @cheezus last edited by

            @cheezus
            QML sample source url:https://bugreports.qt.io/browse/QTBUG-53509

            1 Reply Last reply Reply Quote 0
            • C
              cheezus @liuyang last edited by

              @liuyang I'm saying that JavaScript "leaks" ind ifferent ways than C++. If you do not know how JavaScript leaks, you should learn that first.

              liuyang 1 Reply Last reply Reply Quote 0
              • liuyang
                liuyang @cheezus last edited by

                @cheezus
                JavaScipt source doesn't leak now.but QML side still leaks.please .

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post