modelData is not defined for QML ComboBox with more than one role in QAbstractListModel
<p>This appears to be the same (unanswered) issue as here: <a href="https://stackoverflow.com/questions/32862481/qml-combobox-reports-referenceerror-modeldata-is-not-defined">QML Combobox reports ReferenceError: modelData is not defined</a> .  The closest (closed) bug in the QT database I can find is: <a href="https://bugreports.qt.io/browse/QTBUG-31135" rel="nofollow noreferrer">https://bugreports.qt.io/browse/QTBUG-31135</a> so I'm not sure that this is the same issue. I'm running PyQt5 v5.5 and python 3.4.3.</p>

<p>I'm implementing a QAbstractListModel in PyQt5, and have distilled the code down to the issue at hand:</p>

<pre><code># ExampleModel.py

class ExampleModel(QAbstractListModel):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.items = []

        for t in range(0,10):
            self.items.append({'text': t, 'myother': 'EXAMPLE'})

    def data(self, index, role):
        key = self.roleNames()[role]
        return self.items[index.row()][key.decode('utf-8')]

    def rowCount(self, parent=None):
        return len(self.items)

    def roleNames(self):
        return {Qt.UserRole + 1: b'text',
                Qt.UserRole + 2: b'myother'}
</code></pre>

<p>And the related QML:</p>

<pre><code># example.qml
...
ComboBox { // Displays blank entires + throws ReferenceError
    id: comboExample
    model: ExampleModel{}
    textRole: 'text'  # This was the missing line to make this work.
}

ListView {  // Works Correctly
    id: listExample
    model: ExampleModel{}
    delegate: Text {
        text: myname + " " + myother
    }
}
...
</code></pre>

<p>When I run this, the combo box has 10 blank entries, and the console error log shows:</p>

<blockquote>
  <p>[path]/ComboBox.qml:562: ReferenceError: modelData is not defined</p>
</blockquote>

<p>(x 10)</p>

<p>Now, if I modify the roleNames() code in ExampleModel.py above to the following:</p>

<pre><code>def roleNames(self):
    return {Qt.UserRole + 1: b'myname'}
</code></pre>

<p>the ComboBox works correctly.</p>

<p>Am I missing a key concept here? I don't want to implement my model twice (once for this ComboBox workaround.) </p>

<h2>Edit</h2>

<p>By adding Mitch's suggestion to example.qml above, this problem is fixed.
The code has been updated accordingly.</p>