how to implement code completion in qt

i am writing an ide using qt (on c++) and i need to add auto completion feature to it

so i want to know :

how to do that (i am using qtPlainTextEdit) ?

what the data structure i should use ?


I think you should take a look at this:

I used this example to understand CodeCompletion and I think it is fine :)

[edit] Qt has a own class for such purpose called QCompleter:

I also need to write a code completer in Qt and the first link Tobias provided is the document to look at. It is comprehensive and clear and worked for me. I am sure will work for you.

If you need a code completer in lineEdit, it's pretty simple (from the QCompleter documentation):

QStringList wordList;
wordList << "one" << "two" << "three" << "four" << "five";
QLineEdit *lineEdit = new QLineEdit(this);

QCompleter *completer = new QCompleter(wordList, this);

However a QPlainTextEdit, or QTextEdit don't have a built-in setCompleter() member function so you must follow the custom code completer tutorial.

That's a big, complex feature. I'd look at how it's been done in the Qt Creator.

Need Your Help