I have a dialog where user selects file(s). I added QCompleter
to the line edit, which automatically suggests next file name:
However if user clicks on file, the suggestions disappear:
I want them to reappear if directory is selected and display the files in that directory. I tried to do this inside the QLineEdit::textChanged
signal. I connected it to such slot:
void ImportFromExcelDialog::pathChanged( const QString& path )
if(path.length()>0) {
QFileInfo info(path);
if( info.exists() && info.isFile() && info.isReadable() ) {
// File selected, do stuff with it
}
else {
// If a directory
if((info.exists() && info.isDir())) {
if(!path.endsWith("/"))
ui->fileLineEdit->setText(path + "/");
// Assume QCompleter* completer_; which is set in constructor
if(completer_!=nullptr)
completer_->complete();
}
}
}
}
The problem is that calling complete()
shows the old list of files, the one for parent directory:
I can click telemetrie as many times as I want and the display won't change.
So how to force QCompleter
to reappear and handle the new value of the text field?