Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, July 2007
QComboBox + QAbstractModel findText problem?


Message 1 in thread

To answer my own question: I found the problem. I copied the
data() example from the model/view docs for my model, which contains the
following code snippet:

 if (role == Qt::DisplayRole)
         return stringList.at(index.row());

A model like this is not 100% compatible with a QComboBox. To get the
findText() method working, the string must also be returned for the
Qt::EditRole, i.e. the snippet must look like this:

 if (role == Qt::DisplayRole || role == Qt::EditRole)
         return stringList.at(index.row());

Guido

P.S. should stop using the 'reply' button to post here. Not nice for
threading. Wonder why nobody yelled at me, yet. :-)

> I have here a minor problem. Perhaps someone could point me in the
> right direction. I have a QComboBox, which I pass a custom made
> QAbstractListMode derived model. I implemented data() and count().
> Everything looks good so far, the QComboBox is filled with the model's
> text data. However, the findText method always returns -1,
> even if the string is in the box.

--
 [ signature omitted ]