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. Reading data from an excel file using qfiledislog
Forum Updated to NodeBB v4.3 + New Features

Reading data from an excel file using qfiledislog

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 1.3k Views 2 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.
  • jsulmJ jsulm

    @emeka_o QFileDialog does not open any files. QFile does...

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

    @jsulm oh my bad. Can I use qfile to open an excel file to read the data from it and store it?

    jsulmJ 1 Reply Last reply
    0
    • E emeka_o

      @jsulm oh my bad. Can I use qfile to open an excel file to read the data from it and store it?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @emeka_o Of course you can. But then you will have to parse the file by yourself which is a hard to achieve task as the format is complex. That's why I gave you a link where it is described how you can read Excel files.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • E Offline
        E Offline
        emeka_o
        wrote on last edited by
        #7

        Would it be the same method for a .txt file?

        mrjjM 1 Reply Last reply
        0
        • E emeka_o

          Would it be the same method for a .txt file?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @emeka_o

          Hi
          What type of text file ?

          say if you had a comma separated values file ( a text file )
          then it would be much easier to read into a Qt program and do something with it.

          so if you saved from excel a CSV file it would be easy to read in Qt.

          E 1 Reply Last reply
          0
          • mrjjM mrjj

            @emeka_o

            Hi
            What type of text file ?

            say if you had a comma separated values file ( a text file )
            then it would be much easier to read into a Qt program and do something with it.

            so if you saved from excel a CSV file it would be easy to read in Qt.

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

            @mrjj how do I open and read a csv file to get the variables to store in let’s say a vector

            mrjjM 1 Reply Last reply
            0
            • E emeka_o

              @mrjj how do I open and read a csv file to get the variables to store in let’s say a vector

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #10

              @emeka_o

              Hi
              With Qfile and QString and its split function.
              You would loop over each line and then split on comma or Tab (as excel uses)
              like here. first answer
              https://stackoverflow.com/questions/27318631/parsing-through-a-csv-file-in-qt

              or you could use a lib
              https://github.com/iamantony/qtcsv

              1 Reply Last reply
              4
              • E Offline
                E Offline
                emeka_o
                wrote on last edited by
                #11

                Will this be able to open any csv file without putting the file name in the code?

                jsulmJ 1 Reply Last reply
                0
                • E emeka_o

                  Will this be able to open any csv file without putting the file name in the code?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  @emeka_o said in Reading data from an excel file using qfiledislog:

                  Will this be able to open any csv file without putting the file name in the code?

                  For that use QFileDialog to let the user select the file to open and then open it using QFile, is really not that hard. Or what is your use case?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  3
                  • E Offline
                    E Offline
                    emeka_o
                    wrote on last edited by
                    #13

                    I want the user to be able to select the csv file and I want to be able to save the the data in variables

                    JonBJ 1 Reply Last reply
                    0
                    • E emeka_o

                      I want the user to be able to select the csv file and I want to be able to save the the data in variables

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #14

                      @emeka_o
                      So exactly what @jsulm said then. QFileDialog allows the user to pick just the filename, and QFile accepts that filename to open the file. Two separate things.

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        emeka_o
                        wrote on last edited by
                        #15

                        thank you

                        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