I all, I just follow this great example:
http://qt-project.org/doc/qt-4.8/tools-customcompleter.html
I copy the code exactly except some change with the modelFromFile method, here is it:
QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
{
QStringList words;
words
<< "break"
<< "default"
<< "func"
<< "interface"
<< "select"
<< "case"
<< "defer"
<< "go"
<< "map"
<< "struct"
<< "chan"
<< "else"
<< "goto"
<< "package"
<< "switch"
<< "const"
<< "fallthrough"
<< "if"
<< "range"
<< "type"
<< "continue"
<< "for"
<< "import"
<< "return"
<< "var";
return new QStringListModel(words, completer);
}
The strange thing is when I type “fal” I’m waiting for “fallthrough” pop out, but I see nothing. It can work with “break” and some but not all words.
I’m using Kubuntu 12.04 and my partner with Ubuntu 12.04 get this behavior.
Qt Creator 2.4.1
Based on Qt 4.8.0 (32 bit)
QStringListModel is able to complete word when list given in argument is sorted list. Your list is unsorted, so it has right not to work 🙂