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. Using QCompleter with a custom Model.
Forum Updated to NodeBB v4.3 + New Features

Using QCompleter with a custom Model.

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

    Hi there!

    I having problems with a QCompleter. That I have is a QLineEdit in witch the user must to put a Customer name and I want to autocomplete with the names of the customers on my system. I have the Customer class witch has the name method and a class CustomerCollection to handle a list of customers.

    To use the QCompleter, I choose for create an Item Model, well, I create the class CustomerItemModel and it's content is:

    @
    class CustomerItemModel : public QAbstractListModel
    {
    Q_OBJECT

    public:
    CustomerItem(const CustomerCollection &col, QObject *parent = 0)
    : QAbstractListModel(parent), collection(col) {}

    int rowCount(const QModelIndex &parent = QModelIndex()) const{
    return this->collection.count();
    }
    QVariant data(const QModelIndex &index, int role) const{
    return collection.at(index.row()).name();
    }

    private:
    CustomerCollection collection;
    };
    @

    Well... I create a QCompleter with a collection of all the customers on my system, but the autocomplete does not works...

    Any suggestion?
    Thanks!

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joonhwan
      wrote on last edited by
      #2

      Consider following statements in Qt document

      bq. When subclassing QAbstractItemModel, at the very least you must implement index(), parent(), rowCount(), columnCount(), and data(). These functions are used in all read-only models, and form the basis of editable models.

      In your case, your class derived from QAbstractListModel which is override index() function, so you should implement remained virtual functions. First check whether your gui code is correct by using just simple QStringList (using QCompleter(QStringList&...) constructor) is also good starting point I think.

      Good luck

      joonhwan at gmail dot com

      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