This is odd: I tried to translate this into Python. The data is loaded just fine and queries work - they return the top 20 results just fine - but no dropdown with the completions is rendered when I type into the QLineEdit. Am I doing something obvious wrong? Do you have any ideas how to put hooks into this thing to see what's going on? (which methods of the QSqlQueryModel does QCompleter call?)
@
class TestCompleterModel(QtSql.QSqlQueryModel):
def init(self, terms, view_terms = 10, parent = None):
super(TestCompleterModel, self).init(parent)
self.db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
self.db.setDatabaseName(':memory:')
if self.db.open():
self.query = QtSql.QSqlQuery()
self.query.exec_('create table options(val varchar(100))')
self.query.prepare('insert into options values (?)')
for term in terms:
self.query.bindValue(0, term)
self.query.exec_()
self.query.exec_('select count(*) from options')
print 'rows in SQLITE:'
while self.query.next():
print self.query.value(0)
self.query.prepare("select val from options where val like ? || '%' order by val limit 20")
self.query.bindValue(0, 'aspi')
self.query.exec_()
print 'top 20 matches:'
while self.query.next():
print self.query.value(0)
self.view_terms = view_terms
self.terms = sorted(terms)
self.num_terms = len(terms)
self.line_edit = parent
self.completion_prefix = ''
@QtCore.Slot()
def setCompletionPrefix(self, prefix):
print 'setCompletionPrefix', prefix
self.completion_prefix = prefix
self.query.prepare("select val from options where val like ? || '%' order by val limit 20")
self.query.bindValue(0, prefix)
self.query.exec_()
self.setQuery(self.query)
class TestLineEdit(QtGui.QLineEdit):
def init(self, terms = None, parent = None):
super(TestLineEdit, self).init(parent)
self.et = initialLoadEmTree()
terms = sorted(self.et.all_terms_and_syns())
print 'Number of terms', len(terms)
self.completer = QtGui.QCompleter(self)
self.completer.setMaxVisibleItems(10)
self.completion_model = TestCompleterModel(terms, 10, self)
self.completer.setModel(self.completion_model)
self.textEdited.connect(self.completion_model.setCompletionPrefix)
@
Many thanks
Patrick