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. [Solved]Subclassing QAbstractProxyModel issue
Forum Updated to NodeBB v4.3 + New Features

[Solved]Subclassing QAbstractProxyModel issue

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.1k 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.
  • R Offline
    R Offline
    ranger0
    wrote on last edited by
    #1

    Hi guys,

    I'm trying to subclass QAbstractProxyModel in order to implement my own search engine on a data set.

    I had to implement these functions:

    @

    QModelIndex proxymodel::mapFromSource(const QModelIndex &sourceIndex) const
    {
    return QModelIndex();
    }

    QModelIndex proxymodel::mapToSource(const QModelIndex &proxyIndex) const
    {
    if(proxyIndex.isValid())
    return createIndex(resultado.results().at(proxyIndex.row()).x,buscacoluna);
    else
    return QModelIndex();
    }

    QModelIndex proxymodel::parent(const QModelIndex &child) const
    {
    return QModelIndex();
    }

    QModelIndex proxymodel::index(int row, int column, const QModelIndex &parent) const
    {
    return createIndex(row,column);
    }

    int proxymodel::rowCount(const QModelIndex &parent) const
    {
    return resultado.results().count();
    }

    int proxymodel::columnCount(const QModelIndex &parent) const
    {
    return 1;
    }

    QVariant proxymodel::data(const QModelIndex &proxyIndex, int role) const
    {
    return resultado.results().at(proxyIndex.row()).dados;
    }

    Qt::ItemFlags proxymodel::flags(const QModelIndex &index) const
    {
    return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
    }
    @

    I'm sure my data function returns a valid QVariant, but my QListView doesn't show any record.

    Does anyone could help me to fix this?

    Thanks.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      ranger0
      wrote on last edited by
      #2

      It was missing a if statement at Data() function preventing to return other holes than DisplayRole.

      Thanks.

      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