[solved] Autocomplete implementation in Qt



  • Hi Guys,

    I have been looking into different ways to implement an autocomplete feature in my application. The way that I think I like best is using the QCompleter class in conjunction with a class that has been subclassed from QAbstractItemModel. I want this model to be able to hold function names taken from files and store them in an object of my class which I assume will use some kind of tree -like structure (Is this the case for classes using QAbstractItemModel? :S)

    Could anyone point me in the right direction to begin work on this? I am currently unsure how to read in the function names, do I just a regex to pick up anything between say the word 'void' and an opening bracket '('?
    How would I set up the hierarchy (tree)? How would I link specific objects to the functions that it can use?

    Any help would be very much appreciated
    Thanks


  • Moderators

    You can definitely examine Qt Creator source code, it contains 2 code parsers: one custom-made by Qt Project/ Digia, and one based on clang.



  • Thanks sierdzio. I have been looking at the 'Custom Completer Example' that I found here http://qt-project.org/doc/qt-4.8/tools-customcompleter.html.

    I am currently writing an algorithm using QRegExp to read function names and hold them in a tree structure like the example explains. Once I get somewhere with/have no more question I will mark this as solved ;)


  • Moderators

    Just remember that in Qt 5 QRegExp is considered deprecated. The replacement, much more powerful, is called "QRegularExpression":http://qt-project.org/doc/qt-5.1/qtcore/qregularexpression.html.



  • Thanks for the tip. I have been using QRegExp the whole way through the project haha I shall have to go back and fix that


  • Moderators

    Well, it's not wrong to keep it: QRegExp will not be removed as long as Qt 5 exists. It's just about knowing the general direction of the project :)



  • Marking this as solved as I was able to get what needed using a tree model implementation of QAbstractItemModel in conjunction with a QCompleter


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.