[Qt-interest] Using QCompleter with QFileSystemModel

Brian McKinnon bpmckinnon.qt at gmail.com
Thu Jul 7 16:15:45 CEST 2011


Hi Everyone,

I'm having some trouble with the QCompleter using QFileSystemModel on a
QLineEdit.  I'm trying to set a relative path that will be the base for
other files.  My code in the constructor of my dialog looks like this:

        // This is pretty much cut and paste from the docs
        QCompleter * completer = new QCompleter(this);
        QFileSystemModel * model = new QFileSystemModel(completer);
        model->setFilter(QDir::Dirs | QDir::Drives | QDir::AllDirs |
QDir::NoDotAndDotDot);
        model->setRootPath(tr(""));
        completer->setModel(model);
        mUi.relativePathLineEdit->setCompleter(completer);

        // I added this since entering a new path wasn't popping up any
options
        connect(model, SIGNAL(directoryLoaded(QString)),
SLOT(directoryLoadedForCompleter(QString)));

I'm using QSettings to save the last value and it is reloaded using:

    mUi.relativePathLineEdit->setText(settings.value("relativePath",
tr("")).toString());

I added this function to popup the once the directory loading is complete

void EditorDialog::directoryLoadedForCompleter(const QString & path)
{
    if(mUi.relativePathLineEdit->hasFocus())
    {
        mUi.relativePathLineEdit->completer()->complete();
    }
}

Most of this is working but if I start in a deep directory from the settings
that get loaded, for example C:/path/to/here, then nothing gets loaded until
I back off to C:/path.

Am I missing a step?  Has anyone had any luck using the QFileSystemModel
with QComplete;

I'm using Qt 4.7.3 on Windows 7 64 bit with Visual Studio 2008.

Thanks,
Brian!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110707/17cb3c9f/attachment.html 


More information about the Qt-interest-old mailing list