Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Help using QCompleter with QFileSystemModel



  • I want to adapt the 'customcompleter' example (http://doc.qt.digia.com/qt/tools-customcompleter.html) to use a file system completer instead of reading out of the word list.

    The docs say you can use a QFileSystemModel using the following (http://doc.qt.digia.com/qt/qcompleter.html):

    @ QCompleter *completer = new QCompleter(this);
    completer->setModel(new QDirModel(completer));
    lineEdit->setCompleter(completer);
    @

    [Typo, btw.] So in the example, I tried changing:

    @ completer->setModel(modelFromFile(":/resources/wordlist.txt"));@

    to

    @ QFileSystemModel * model = new QFileSystemModel(completer);
    model->setRootPath("");
    completer->setModel(model);
    @

    (I also tried it without the setRootPath call, passing in "." and "/", and with QDirModel instead.)

    It no longer works: the completion window does not appear either on its own or when called with ctrl-E. What am I doing wrong?



  • Oh, I guess I should say that I'm using Qt 4.8.1 on Linux.


Log in to reply