Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. table not getting created completely.

table not getting created completely.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 278 Views
  • 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.
  • ashajgA Offline
    ashajgA Offline
    ashajg
    wrote on last edited by
    #1

    Hi

    I have written a code for creating table. but when I am running that code, some times table is not getting created(only headers are visible ) and some times it works perfectly. This problem is more persistent on embedded board (IMX6) than windows and I am not getting any error.

    QML

    
        /************************************************/
        Rectangle
        {   id: tableParent
            anchors.left: parent.left
            anchors.leftMargin: sertabLeftMargin
            anchors.top: parent.top
            anchors.topMargin: sertabTopMargin+componentStatusTable.tableRowHeight
            height:childrenRect.height
            width:childrenRect.width
            border.color:componentStatusTable.tableViewDelegateBorderColor
    
            CustomTableView {
                id: componentStatusTable
                model: proxyServiceLog
                ScrollBar.vertical: sBar
                width:  sertabTimWidth+sertabTypWidth+sertabMesWidth
                height: sertabTableRows* tableRowHeight
                delegate: Rectangle {
                    id: textContainer
                    implicitWidth:(column === 0) ? (sertabTimWidth):(column === 1) ? (sertabTypWidth) : (sertabMesWidth)
                    implicitHeight: sertabHeaderHeight
                    border.color: tableViewDelegateBorderColor
                    color: (row%2===0) ? tableRowColorLight:tableRowColorDark
                    Text {
                        anchors.left: parent.left
                        anchors.leftMargin: tableViewTextMargin
                        verticalAlignment: Text.AlignVCenter
                        color: tableDataTextColor
                        font.pixelSize: tableTextFontSize
                        anchors.verticalCenter:parent.verticalCenter
                        text: qsTrId(tableData)
                        wrapMode: Text.WordWrap
                    }
                }
                Component.onCompleted: { flag = 1;}
            }
        }
        
    
    

    CustomTableview.qml

    import QtQuick 2.0
    import QtQuick 2.12
    
    TableView {
        //Data arriving from Component styling XML
        property string tableViewDelegateBorderColor: component.getComponentXmlDataByTag("CustomTableView","TableViewDelegateBorderColor")
        property string tableHeaderDataBgColor: component.getComponentXmlDataByTag("CustomTableView","TableHeaderDataBgColor")
        property string tableBodyDataBgColor: component.getComponentXmlDataByTag("CustomTableView","TableBodyDataBgColor")
        property string tableHeaderTextColor: component.getComponentXmlDataByTag("CustomTableView","TableHeaderTextColor")
        property string tableDataTextColor: component.getComponentXmlDataByTag("CustomTableView","TableDataTextColor")
        property int tableHeaderTextFontSize: component.getComponentXmlDataByTag("CustomTableView","TableHeaderTextFontSize")
        property int tableDataTextFontSize: component.getComponentXmlDataByTag("CustomTableView","TableDataTextFontSize")
        property int tabDataLeftMarginFromTableBorder: component.getComponentXmlDataByTag("CustomTableView","TabDataLeftMarginFromTableBorder")
        property int tableViewDefaultRowWidth: component.getComponentXmlDataByTag("CustomTableView","TableViewDefaultRowWidth")
        property int tableViewDefaultRowHeight: component.getComponentXmlDataByTag("CustomTableView","TableViewDefaultRowHeight")
    
        //Data arriving from QML/ Parent that instantiates Table view component
        property int tableRowWidth: tableViewDefaultRowWidth
        property int tableRowHeight: tableViewDefaultRowHeight
    
        property int tableRowCount: model.rowCount()
        property int tableColumnCount: model.columnCount()
    
        height: tableRowCount * tableRowHeight
    
        clip: true
        interactive: true
        boundsBehavior: Flickable.StopAtBounds
    
        delegate: Rectangle {
            id: textContainer
            implicitWidth: tableRowWidth
            implicitHeight: tableRowHeight
            border.color: tableViewDelegateBorderColor
            color: headerData ? tableHeaderDataBgColor : tableBodyDataBgColor
    
            Text {
                anchors.fill: parent
                anchors.leftMargin: tabDataLeftMarginFromTableBorder
                verticalAlignment: Text.AlignVCenter
                color: textContainer.color == tableHeaderDataBgColor ? tableHeaderTextColor : tableDataTextColor
                font.pixelSize:  textContainer.color == tableHeaderDataBgColor ? tableHeaderTextFontSize : tableDataTextFontSize
                text: qsTrId(tableData)
                wrapMode: Text.WordWrap
            }
        }
    
    }
    

    table model cpp

    #include "servicelogtablemodel.h"
    
    ServiceLogTableModel *ServiceLogTableModel::m_staticInstance = nullptr;
    
    ServiceLogTableModel::ServiceLogTableModel(QObject *parent)
    {
    
    }
    
    int ServiceLogTableModel::rowCount(const QModelIndex &) const
    {
        return table.size();
    }
    
    int ServiceLogTableModel::columnCount(const QModelIndex &) const
    {
        return table.at(0).size();
    }
    
    QVariant ServiceLogTableModel::data(const QModelIndex &index, int role) const
    {
        if (role != TableDataRole)
            return QVariant();
    
        if(role == TableDataRole) {
            return table.at(index.row()).at(index.column());
        }
        return QVariant();
    }
    
    QHash<int, QByteArray> ServiceLogTableModel::roleNames() const
    {
        QHash<int, QByteArray> roles;
        roles[TableDataRole] = "tableData";
        roles[HeaderRole] = "headerData";
        return roles;
    
    }
    
    void ServiceLogTableModel::updateTable(QString time, QString type, QString message)
    {
        i_time = time;
        i_type = type;
        i_message= message;
        qDebug()<<"TIME IS "<<i_time<<"\n"<<"TYPE IS"<<i_type<<"\n"<<"MESSAGE IS "<<i_message<<"\n";
        qDebug()<<"INDEX : "<<table.size();
        qDebug() << "TableModel:" << table;
        beginInsertRows(QModelIndex(), table.size(),table.size());
        table.append({i_time,i_type,i_message});
        endInsertRows();
    }
    
    void ServiceLogTableModel::addInitialData()
    {
        table.append({"31-Oct-2018 11:34","Event","Service mode"});
        table.append({"08-Oct-2018 12:30","Event","System On"});
        table.append({"06-Oct-2018 12:40","Alarm","Ppeak low inactive"});
        table.append({"20-Oct-2018 13:50","Alarm","Apnea inactive"});
        table.append({"22-Oct-2018 11:34","Event","Service mode"});
        table.append({"03-Oct-2018 12:30","Event","System On"});
        table.append({"04-Oct-2018 12:40","Alarm","Ppeak low inactive"});
        table.append({"01-Oct-2018 13:50","Alarm","Apnea inactive"});
        table.append({"31-Oct-2018 17:34","Event","Service mode"});
        table.append({"31-Oct-2018 18:30","Event","System On"});
        table.append({"31-Oct-2018 12:40","Alarm","Ppeak low inactive"});
        table.append({"31-Oct-2018 13:50","Alarm","Apnea inactive"});
        table.append({"31-Oct-2018 11:34","Event","Service mode"});
        table.append({"08-Oct-2018 12:30","Event","System On"});
    //    table.append({"06-Oct-2018 12:40","Alarm","Ppeak low inactive"});
    //    table.append({"20-Oct-2018 13:50","Alarm","Apnea inactive"});
    //    table.append({"22-Oct-2018 11:34","Event","Service mode"});
    //    table.append({"03-Oct-2018 12:30","Event","System On"});
    //    table.append({"04-Oct-2018 12:40","Alarm","Ppeak low inactive"});
    //    table.append({"01-Oct-2018 13:50","Alarm","Apnea inactive"});
    //    table.append({"31-Oct-2018 17:34","Event","Service mode"});
    //    table.append({"31-Oct-2018 18:30","Event","System On"});
    //    table.append({"31-Oct-2018 12:40","Alarm","Ppeak low inactive"});
    //    table.append({"31-Oct-2018 13:50","Alarm","Apnea inactive"});
    //    table.append({"31-Oct-2018 11:34","Event","Service mode"});
    //    table.append({"08-Oct-2018 12:30","Event","System On"});
    //    table.append({"06-Oct-2018 12:40","Alarm","Ppeak low inactive"});
    //    table.append({"20-Oct-2018 13:50","Alarm","Apnea inactive"});
    //    table.append({"22-Oct-2018 11:34","Event","Service mode"});
    //    table.append({"03-Oct-2018 12:30","Event","System On"});
    //    table.append({"04-Oct-2018 12:40","Alarm","Ppeak low inactive"});
    //    table.append({"01-Oct-2018 13:50","Alarm","Apnea inactive"});
    //    table.append({"31-Oct-2018 17:34","Event","Service mode"});
    //    table.append({"31-Oct-2018 18:30","Event","System On"});
    //    table.append({"31-Oct-2018 12:40","Alarm","Ppeak low inactive"});
    //    table.append({"31-Oct-2018 13:50","Alarm","Apnea inactive"});
    }
    
    ServiceLogTableModel *ServiceLogTableModel::getStaticInstance()
    {
        if(m_staticInstance == nullptr)
            m_staticInstance = new ServiceLogTableModel();
        return m_staticInstance;
    }
    
    QSortFilterProxyModel *ServiceLogTableModel::getProxyModelInstance()
    {
        proxyModel = new QSortFilterProxyModel();
        return proxyModel;
    }
    
    void ServiceLogTableModel::sort(int column, Qt::SortOrder order)
    {
        proxyModel->sort(column,order);
    }
    
    void ServiceLogTableModel::setFilteringOptions(QString eventName)
    {
        if(eventName == "All")
            invalidateSortingFiltering();
        else {
            proxyModel->setFilterKeyColumn(1);
            proxyModel->setFilterRegExp(eventName);
        }
    
    }
    
    void ServiceLogTableModel::invalidateSortingFiltering()
    {
        proxyModel->setFilterRegExp(QString());
    }
    

    I am filling my model with data==>
    main.cpp

    ServiceLogTableModel *t1 = ServiceLogTableModel::getStaticInstance();//Model
     t1->addInitialData();
    QSortFilterProxyModel  *proxyModel =t1 ->getProxyModelInstance();
     proxyModel->setSourceModel(t1);
     proxyModel->setSortRole(ServiceLogTableModel::TableDataRole);
     proxyModel->setFilterRole(ServiceLogTableModel::TableDataRole);
    

    how can I solve this issue so that table should get completely created?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adomanim
      Banned
      wrote on last edited by adomanim
      #2
      This post is deleted!
      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