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. Searching a QString in QSqlRelationalTableModel witch match doesn't return a result
Qt 6.11 is out! See what's new in the release blog

Searching a QString in QSqlRelationalTableModel witch match doesn't return a result

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 615 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.
  • J Offline
    J Offline
    Johannis259
    wrote on last edited by Johannis259
    #1

    Hello,

    What am I doing wrong? I have been looking for a solution for quite some time now. The first part of the code works (search in a for loop for a QString in a model). The second part should do the same but doesn't return any valid index.

    ClubsModel is subclassed from QSqlRelationalTableModel. ClubsModelProxy from QSortFilterProxyModel.

    
    int ClubsModel::getRank(const int clubId)
    {
        int nrofrows = clubsModelProxy->rowCount();
        int rank=0;
    
        QString clubName=data(index(clubId, CLUBNAME, QModelIndex()), Qt::DisplayRole).toString();
    
        for (int row = 0; row < nrofrows; ++row) {
            QModelIndex idx=clubsModelProxy->index(row,CLUBNAME,QModelIndex());
            if (clubsModelProxy->data(idx).toString()==clubName){
                rank=idx.row()+1;
                break;
            }
        }
    
        QModelIndexList indexList=clubsModelProxy->match(index(0,0),Qt::DisplayRole, QVariant::fromValue(clubName), -1, Qt::MatchFixedString);
        qDebug()<<indexList.count();
        return rank;
    }
    

    What do I overlook?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Is CLUBNAME's value 0 ?

      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
      1
      • J Offline
        J Offline
        Johannis259
        wrote on last edited by
        #3

        Thank you! CLUBNAME is not 0. CLUBNAME is defined as const int CLUBNAME=2. It's refering to the third row of the model. That row contains club names.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

          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