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: selecting the wrong type of file
Forum Updated to NodeBB v4.3 + New Features

Qfiledialog: selecting the wrong type of file

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 426 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.
  • E Offline
    E Offline
    emeka_o
    wrote on last edited by
    #1

    I want to open .csv files only and I have been successful doing this.
    However if another type of file is opened (.txt or excel) the program crashes.
    How do I handle this error. If the user selects a wrong type of file.

    Pl45m4P 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @emeka_o said in Qfiledialog: selecting the wrong type of file:

      How do I handle this error.

      You have the filename so you know it's extension. But since an extension does not tell you anything about the real content of a file you should fix your program so it does not crash even the csv file does not contain the expected content.

      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
      3
      • E emeka_o

        I want to open .csv files only and I have been successful doing this.
        However if another type of file is opened (.txt or excel) the program crashes.
        How do I handle this error. If the user selects a wrong type of file.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @emeka_o said in Qfiledialog: selecting the wrong type of file:

        .csv files only

        You could add a filter to show csv files only.

        Your program will still crash, when some other file types are opened but it's not possible to select something else than csv files.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        E 1 Reply Last reply
        2
        • Pl45m4P Pl45m4

          @emeka_o said in Qfiledialog: selecting the wrong type of file:

          .csv files only

          You could add a filter to show csv files only.

          Your program will still crash, when some other file types are opened but it's not possible to select something else than csv files.

          E Offline
          E Offline
          emeka_o
          wrote on last edited by
          #4

          @Pl45m4 how do I add that filter?

          Pl45m4P 1 Reply Last reply
          0
          • E emeka_o

            @Pl45m4 how do I add that filter?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @emeka_o

            dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)"));
            

            In the above example, the filter is set to "Images (*.png *.xpm *.jpg)", this means that only files with the extension png, xpm, or jpg will be shown in the QFileDialog.

            (from: https://doc.qt.io/qt-5/qfiledialog.html#details)


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            1

            • Login

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