Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileDialog Bug?

QFileDialog Bug?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 5 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    I have created a QFileDialog and use getSaveFileName to request the user for a file name. I use the option to specify allowed file name extensions (just .slx in this case). The listed existing files are properly filtered according to the specified file name extensions but when the user starts typing a file name, the list suggested file names is not filtered according to the specified file name extensions and one can in fact select a file name with an invalid extension. To me this seems a bug or have others experienced the same and solved this somehow?

    Some screen shots to illustrate the situation:
    Step1: Executing QFileDialog::getSaveFileName
    Step2: Entering text with suggested file name list
    Step3: One can select an invalid file name

    aha_1980A 1 Reply Last reply
    0
    • ModelTechM ModelTech

      I have created a QFileDialog and use getSaveFileName to request the user for a file name. I use the option to specify allowed file name extensions (just .slx in this case). The listed existing files are properly filtered according to the specified file name extensions but when the user starts typing a file name, the list suggested file names is not filtered according to the specified file name extensions and one can in fact select a file name with an invalid extension. To me this seems a bug or have others experienced the same and solved this somehow?

      Some screen shots to illustrate the situation:
      Step1: Executing QFileDialog::getSaveFileName
      Step2: Entering text with suggested file name list
      Step3: One can select an invalid file name

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @ModelTech,

      can you show the code you use the create the dialog?

      Qt has to stay free or it will die.

      1 Reply Last reply
      0
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by
        #3

        I hope this parts suffices. It is primarily the last line in this code to get the QFileDialog, but I also included the part where I create the Filter of allowed File Extensions

                QStringList Extensions;
                QString Filters;
                for (int i = 0; i < Plugin->exportFileFilters().size(); ++i) {
                    Filters += Plugin->exportFileFilters()[i];
                    if (i < Plugin->exportFileFilters().size())
                        Filters += ";;";
                    QStringList Splitted = Plugin->exportFileFilters()[i].split(QRegExp("\\(|,|\\)"), QString::SkipEmptyParts);
                    for (int j = 1; j < Splitted.size(); ++j)
                        if (Splitted[j].contains("*."))
                            Extensions.append(Splitted[j].trimmed().remove("*."));
                }
        
                QString FileName = QFileDialog::getSaveFileName(this, tr("Export Model"), RecentLocation, Filters);
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          This has nothing to do with Qt (esp. since this is the native Windows file dialog) - it's the same for me with a non-Qt program on Windows 8.1 ...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          4
          • ModelTechM Offline
            ModelTechM Offline
            ModelTech
            wrote on last edited by ModelTech
            #5

            Ah, it is windows 8 indeed on which I saw this. I can also try on other platforms.

            Edit: And indeed, it's only on windows (also windows 10) but not on Linux. So, its a clear Microsoft bug... Thanks :)

            JonBJ 1 Reply Last reply
            0
            • ModelTechM ModelTech

              Ah, it is windows 8 indeed on which I saw this. I can also try on other platforms.

              Edit: And indeed, it's only on windows (also windows 10) but not on Linux. So, its a clear Microsoft bug... Thanks :)

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @ModelTech
              When using Windows or Linux file dialogs at least, the filename extension type is used to filter what is offered when loading/saving, and to provide a default extension if none specified when saving. However, they do not prevent the user typing in anything else he pleases regardless.

              ModelTechM 1 Reply Last reply
              0
              • JonBJ JonB

                @ModelTech
                When using Windows or Linux file dialogs at least, the filename extension type is used to filter what is offered when loading/saving, and to provide a default extension if none specified when saving. However, they do not prevent the user typing in anything else he pleases regardless.

                ModelTechM Offline
                ModelTechM Offline
                ModelTech
                wrote on last edited by
                #7

                @JonB : Yes, that's why I actually check what extension is eventually selected and if it is not what it should be, I add it. This is in the code right after the piece that I gave above. Thanks

                1 Reply Last reply
                0
                • Maickonn RichardM Offline
                  Maickonn RichardM Offline
                  Maickonn Richard
                  wrote on last edited by
                  #8

                  This is no longer a Qt problem, but rather the operating system itself. Try doing the same thing with Paint, for example.

                  Look:
                  0_1532627765212_screen.JPG

                  1 Reply Last reply
                  1
                  • ModelTechM Offline
                    ModelTechM Offline
                    ModelTech
                    wrote on last edited by
                    #9

                    It's indeed only on windows (also windows 10) but not on Linux. So, its a clear Microsoft bug...

                    JonBJ 1 Reply Last reply
                    1
                    • ModelTechM ModelTech

                      It's indeed only on windows (also windows 10) but not on Linux. So, its a clear Microsoft bug...

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @ModelTech
                      It's not a bug. It's the way Windows chooses to implement the dropdown completer. They deliberately show existing files matching what you've typed regardless of extension, so that you know they exist. I quite like it.

                      1 Reply Last reply
                      0
                      • ModelTechM Offline
                        ModelTechM Offline
                        ModelTech
                        wrote on last edited by
                        #11

                        I perceived it as an inconsistency and I generally do not like inconsistencies too much ;)

                        JonBJ 1 Reply Last reply
                        0
                        • ModelTechM ModelTech

                          I perceived it as an inconsistency and I generally do not like inconsistencies too much ;)

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @ModelTech
                          When you use http://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName it takes a http://doc.qt.io/qt-5/qfiledialog.html#Option-enum parameter. Try passing it QFileDialog::DontUseNativeDialog to get the Qt dialog instead of the native Windows one. See if that behaves differently/more as you like (it'll only take a second)?

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved