[SOLVED] QTableView - with CustomSortFilterProxyModel - how to get row index recursively without user selection.



  • Hi,
    Thanks for taking the time to read my post. I am currently developing a program, where in I use a QTableview with "MySQLQueryModel + CustomSortFilterProxyModel".

    TASK TO ACCOMPLISH:

    Once I finish filtering the data, I need to be able to extract the data from all rows under column 0 (This field contains a unique member ID), from which I can add custom widgets to a layout dynamically.

    ISSUE:
    Right now, I am unable to get the data from any row from column 0. The tableview will be hidden from the user and cannot be viewed.

    Please Help.....

    Thanks and Regards,

    Roahan



  • Solved it myself. Answer was pretty simple. Attaching snippet here.

    this->existingmembermodel = new QSqlQueryModel(this);
    existingmembermodel->setQuery("SELECT * from member_package_current;");
    chmodel = new CheckableProxyModel();
    chmodel->setDynamicSortFilter(true);
    chmodel->setFilterKeyColumn(-1);
    chmodel->setSourceModel(existingmembermodel);

    In textchanged slot of QLineEdit

    QRegExp regExp(arg1);
    chmodel->setFilterRegExp(regExp);
    int rowcount = chmodel->rowCount();
    qDebug()<<"Row Count : "<<chmodel->rowCount();
    for (int i=0;i<rowcount;i++)
    {
    QModelIndex index = chmodel->index(i,0,QModelIndex());
    qDebug()<<"Available Member ID's"<<chmodel->data(index,Qt::DisplayRole).toString();
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.