PDA

View Full Version : QCompleter with QFileSystemModel not always popping up.



Random Llama
29th April 2013, 04:27
I'm attempting to implement a QCompleter with QFileSystemModel for a QLineEdit to assist the user in typing a local directory. My problem is that the QCompleter does not popup directly after typing in a new path. Here's my code before I go further into detail:


QCompleter *completer = new QCompleter(this);
QFileSystemModel *fsModel = new QFileSystemModel(completer);
fsModel->setRootPath("");
completer->setModel(fsModel);
QLineEdit *lineEdit = new QLineEdit(this);
lineEdit->setCompleter(completer);

I've tested the above code sample using Qt 4.8.x and 5.0.x under Linux, Windows, and OS X and get the same behavior. Let's say the user wants to type in the path: /home/foo/bar. My results are this:


/home/foo // Contents of /home named foo* are displayed
/home/foo/ // The QCompleter disappears entirely

At this point, if the user continues typing the path, or hits backspace and retypes the slash, the QCompleter pops up and works per normal until the next directory is entered whereupon the QCompleter again disappears.

Am I doing something obviously wrong here? Surely this is not the proper behavior; QDirModel works fine here, so I'm left wondering if it's threading related. Any pointers in the right directions are most welcome.