Using Qt 4.8.5
I want a dynamic data model for a QCompleter installed in a QLineEdit. I connect the QLineEdit::textEdited signal to my own function that updates the model, which is my sub-class of QAbstractListModel. It begins as an empty model, but fills itself out on the third keystroke. No completions occur. If I full populate the model when constructed, all works. See code below. I do not know how to notify the QCompleter that the model has changed. I used 'beginResetModel()/endResetModel()' as a try.
// This slot is connected to the QLineEdit::textEdited signal.
void MyaNameModel
::Update(const QString &text
) {
if (text.size() < 3)
{ if (!names.empty())
{ m_names.clear(); // Clear data model's collection of names.
// Notify QCompleter that model has changed.
beginResetModel();
endResetModel();
}
}
else if (m_names.empty())
{ // This extracts information from an external repository via in-house API.
// It fills the container of names.
m_ap.MatchChannel(Glob((text + "*").toAscii().data()), m_names);
// Notify QCompleter that model has changed.
beginResetModel();
endResetModel();
}
}
// This slot is connected to the QLineEdit::textEdited signal.
void MyaNameModel::Update(const QString &text)
{
if (text.size() < 3)
{ if (!names.empty())
{ m_names.clear(); // Clear data model's collection of names.
// Notify QCompleter that model has changed.
beginResetModel();
endResetModel();
}
}
else if (m_names.empty())
{ // This extracts information from an external repository via in-house API.
// It fills the container of names.
m_ap.MatchChannel(Glob((text + "*").toAscii().data()), m_names);
// Notify QCompleter that model has changed.
beginResetModel();
endResetModel();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks