QFileDialog File/Directory field gets truncated



  • I happen to have a weird behavior of QFileDialog in my application. It is not consistent across different stations and debug/optimized versions, but it happens still.

    I have a QfileDialog that opens with QFileDialog::ShowDirsOnly option, the 'File name' label at the bottom reads 'Directory:' and displays the current directory name right next to it.
    I then start to type into that filed: "C:" and the file dialog starts to complete the path.
    When doing so, I get a drop-down menu with all directories under "C:".
    Then, I go ahead and type 't', which yields "C:\t", for which the menu below shows: "temp" and "tmp".
    I then go down with the down arrow and stop at "temp".
    As soon as I select 'temp', the directory field reads: "emp", instead of "C:\temp".

    Does any one have any idea why this is happening and how can I resolve, or work-around it?
    The system is Windows 7 and Qt version is 4.5.1.

    Any comment will be appreciated.
    Thanks.



  • @Raphy

    If possible, post the piece of the code. It would be easy to find the error. :)

    Edit:

    Mostly these couple of lines will do , what you are looking.

    QString file = QFileDialog::getOpenFileName();
     QDir dir = QFileInfo(file).absoluteDir();
    qDebug() << dir;
    


  • @Ni.Sumi
    Thank you for your reply.
    I may have not explained well the problem. The strange behavior I described is inside QFileDialog,
    not after it is closed. It is a weird behavior that occurs while trying to select a directory. There seems to be no interference in QFileDialog behavior from the outside. I have other such dialogs in other parts of my application and they behave properly.
    I was thinking that if someone else came across this kind of behavior and figured out what went wrong, that could give me a hint as for where to look into.



  • @Ni.Sumi said in QFileDialog File/Directory field gets truncated:

    are

    The code creating that dialog is:

    QFileDialog *fd = new QFileDialog();
    fd->setNameFilters(filtersList); // QStringList filterList...
    fd->setDirectory(tmp); // QString tmp...
    fd->setWindowTitle(QString("Open Directory"));
    fd->setFileMode(QFileDialog::Directory);
    fd->setOption(QFileDialog::ShowDirsOnly, true);
    fd->setAcceptMode(QFileDialog::AcceptOpen);
    fd->exec();

    If pictures may help, please let me know how to upload them (could not find a way to do that).

    Thanks.


Log in to reply