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. Selecting multiple files for reading
QtWS25 Last Chance

Selecting multiple files for reading

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5.12read all files
23 Posts 5 Posters 6.0k Views
  • 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.
  • D deleted286
    1 Feb 2021, 14:32

    @JonB If I could think and do all of this at once, I wouldn't ask for help. You don't have to be this hard every time. I'm probably younger than you, and I'm making an effort to learn. It shouldn't be that hard to understand

    C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 1 Feb 2021, 14:34 last edited by Christian Ehrlicher 2 Jan 2021, 14:36
    #8

    @suslucoder But even then you should know how to iterate over a container, sorry.

    https://stackoverflow.com/questions/498455/best-way-to-iterate-through-a-container

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

    D 1 Reply Last reply 1 Feb 2021, 14:42
    4
    • D deleted286
      1 Feb 2021, 14:32

      @JonB If I could think and do all of this at once, I wouldn't ask for help. You don't have to be this hard every time. I'm probably younger than you, and I'm making an effort to learn. It shouldn't be that hard to understand

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 1 Feb 2021, 14:35 last edited by jsulm 2 Jan 2021, 14:36
      #9

      @suslucoder Well this is Qt forum, not basic programming one. That's why people can give somewhat harsh replies if you ask about basic programming stuff not related to Qt. This is something you should understand.
      Iterating trough a list is one of the basic programming concepts. You should do some research for such basic stuff at your own before asking here. For example using Google you can find: https://stackoverflow.com/questions/16825376/qt-foreach-loop-ordering-vs-for-loop-for-qlist

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

      D 1 Reply Last reply 1 Feb 2021, 14:43
      3
      • D deleted286
        1 Feb 2021, 14:32

        @JonB If I could think and do all of this at once, I wouldn't ask for help. You don't have to be this hard every time. I'm probably younger than you, and I'm making an effort to learn. It shouldn't be that hard to understand

        J Offline
        J Offline
        JonB
        wrote on 1 Feb 2021, 14:37 last edited by JonB 2 Jan 2021, 14:38
        #10

        @suslucoder said in Selecting multiple files for reading:

        @JonB If I could think and do all of this at once, I wouldn't ask for help. You don't have to be this hard every time. I'm probably younger than you, and I'm making an effort to learn. It shouldn't be that hard to understand

        I think I explained it very gently & clearly! And told you what you need to do, and explained what the term "iteration" is. So I'm sorry you feel like that, I believe I am one of the people here who is prepared to explain things the most! :) Maybe, if you can, don't take my words as harsh, because they are not intended like that! I'm a pussy cat really :-;

        D 2 Replies Last reply 1 Feb 2021, 14:42
        0
        • J JonB
          1 Feb 2021, 14:37

          @suslucoder said in Selecting multiple files for reading:

          @JonB If I could think and do all of this at once, I wouldn't ask for help. You don't have to be this hard every time. I'm probably younger than you, and I'm making an effort to learn. It shouldn't be that hard to understand

          I think I explained it very gently & clearly! And told you what you need to do, and explained what the term "iteration" is. So I'm sorry you feel like that, I believe I am one of the people here who is prepared to explain things the most! :) Maybe, if you can, don't take my words as harsh, because they are not intended like that! I'm a pussy cat really :-;

          D Offline
          D Offline
          deleted286
          wrote on 1 Feb 2021, 14:42 last edited by
          #11

          @JonB Yes, after seeing the other answers, I understood that you answered my question very kindly. Thank you for your help

          1 Reply Last reply
          1
          • C Christian Ehrlicher
            1 Feb 2021, 14:34

            @suslucoder But even then you should know how to iterate over a container, sorry.

            https://stackoverflow.com/questions/498455/best-way-to-iterate-through-a-container

            D Offline
            D Offline
            deleted286
            wrote on 1 Feb 2021, 14:42 last edited by
            #12

            @Christian-Ehrlicher yes I don't know, is it a shame that I don't know?

            C 1 Reply Last reply 1 Feb 2021, 16:08
            0
            • J jsulm
              1 Feb 2021, 14:35

              @suslucoder Well this is Qt forum, not basic programming one. That's why people can give somewhat harsh replies if you ask about basic programming stuff not related to Qt. This is something you should understand.
              Iterating trough a list is one of the basic programming concepts. You should do some research for such basic stuff at your own before asking here. For example using Google you can find: https://stackoverflow.com/questions/16825376/qt-foreach-loop-ordering-vs-for-loop-for-qlist

              D Offline
              D Offline
              deleted286
              wrote on 1 Feb 2021, 14:43 last edited by
              #13

              @jsulm Okey.

              1 Reply Last reply
              0
              • D deleted286
                1 Feb 2021, 14:42

                @Christian-Ehrlicher yes I don't know, is it a shame that I don't know?

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 1 Feb 2021, 16:08 last edited by
                #14

                @suslucoder Please start with basic c and c++ - everything else will not work out properly. And I'm pretty sure so will tell you the same.

                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
                1
                • J JonB
                  1 Feb 2021, 14:37

                  @suslucoder said in Selecting multiple files for reading:

                  @JonB If I could think and do all of this at once, I wouldn't ask for help. You don't have to be this hard every time. I'm probably younger than you, and I'm making an effort to learn. It shouldn't be that hard to understand

                  I think I explained it very gently & clearly! And told you what you need to do, and explained what the term "iteration" is. So I'm sorry you feel like that, I believe I am one of the people here who is prepared to explain things the most! :) Maybe, if you can, don't take my words as harsh, because they are not intended like that! I'm a pussy cat really :-;

                  D Offline
                  D Offline
                  deleted286
                  wrote on 2 Feb 2021, 12:10 last edited by
                  #15

                  @JonB I want to ask you something.

                  I did it in the way you said. Now i can select multiple files.
                  After selecting, i want to do some operations. But my code do it just for one file. The other files are not functional.

                  Is there any way to do it like, do these for every different files.
                  I will share you my iteration, i hope it is correct:

                  Q_UNUSED(b);
                  
                     QStringList fileNames;
                  
                     fileNames = QFileDialog::getOpenFileNames(nullptr,
                                                               ("choose"), "up.sakla", ("choosen(*.up)"));
                  
                    for (auto xfile : fileNames)
                    {
                  
                     QFile file (xfile);
                     file.open(QIODevice::ReadOnly);
                     QDataStream in(&file);    // read the data serialized from the file
                     QString str;
                     qint32 a;
                       qDebug() << str << a;
                     in >> str >> a;
                  
                  J 1 Reply Last reply 2 Feb 2021, 12:18
                  0
                  • D deleted286
                    2 Feb 2021, 12:10

                    @JonB I want to ask you something.

                    I did it in the way you said. Now i can select multiple files.
                    After selecting, i want to do some operations. But my code do it just for one file. The other files are not functional.

                    Is there any way to do it like, do these for every different files.
                    I will share you my iteration, i hope it is correct:

                    Q_UNUSED(b);
                    
                       QStringList fileNames;
                    
                       fileNames = QFileDialog::getOpenFileNames(nullptr,
                                                                 ("choose"), "up.sakla", ("choosen(*.up)"));
                    
                      for (auto xfile : fileNames)
                      {
                    
                       QFile file (xfile);
                       file.open(QIODevice::ReadOnly);
                       QDataStream in(&file);    // read the data serialized from the file
                       QString str;
                       qint32 a;
                         qDebug() << str << a;
                       in >> str >> a;
                    
                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 2 Feb 2021, 12:18 last edited by jsulm 2 Feb 2021, 12:19
                    #16

                    @suslucoder So, did you select more than one file? How many entries do you have in fileNames? Did you use debugger to see what happens?
                    Add

                    for (auto xfile : fileNames)
                    {
                        qDebug() << xfile;
                    

                    to see what happens. There are so many things you can do to find out what happens...

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

                    D 1 Reply Last reply 2 Feb 2021, 12:21
                    0
                    • J jsulm
                      2 Feb 2021, 12:18

                      @suslucoder So, did you select more than one file? How many entries do you have in fileNames? Did you use debugger to see what happens?
                      Add

                      for (auto xfile : fileNames)
                      {
                          qDebug() << xfile;
                      

                      to see what happens. There are so many things you can do to find out what happens...

                      D Offline
                      D Offline
                      deleted286
                      wrote on 2 Feb 2021, 12:21 last edited by deleted286 2 Feb 2021, 12:22
                      #17

                      @jsulm said in Selecting multiple files for reading:

                      qDebug() << xfile;

                      Yes i select and i can see them. I want to do such a thing:

                      do some operation
                      for every file that i select

                      J J 2 Replies Last reply 2 Feb 2021, 12:22
                      0
                      • D deleted286
                        2 Feb 2021, 12:21

                        @jsulm said in Selecting multiple files for reading:

                        qDebug() << xfile;

                        Yes i select and i can see them. I want to do such a thing:

                        do some operation
                        for every file that i select

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 2 Feb 2021, 12:22 last edited by
                        #18

                        @suslucoder What do you think you print out to qDebug here:

                        QString str;
                        qint32 a;
                        qDebug() << str << a;
                        in >> str >> a;
                        

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

                        D 1 Reply Last reply 2 Feb 2021, 12:23
                        0
                        • J jsulm
                          2 Feb 2021, 12:22

                          @suslucoder What do you think you print out to qDebug here:

                          QString str;
                          qint32 a;
                          qDebug() << str << a;
                          in >> str >> a;
                          
                          D Offline
                          D Offline
                          deleted286
                          wrote on 2 Feb 2021, 12:23 last edited by
                          #19

                          @jsulm I wrote it for see the content of my file. Im asking another thing..

                          J 1 Reply Last reply 2 Feb 2021, 12:24
                          0
                          • D deleted286
                            2 Feb 2021, 12:23

                            @jsulm I wrote it for see the content of my file. Im asking another thing..

                            J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 2 Feb 2021, 12:24 last edited by
                            #20

                            @suslucoder Do you really think the order of the two last lines is correct?

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

                            D 1 Reply Last reply 2 Feb 2021, 12:25
                            1
                            • D deleted286
                              2 Feb 2021, 12:21

                              @jsulm said in Selecting multiple files for reading:

                              qDebug() << xfile;

                              Yes i select and i can see them. I want to do such a thing:

                              do some operation
                              for every file that i select

                              J Offline
                              J Offline
                              J.Hilk
                              Moderators
                              wrote on 2 Feb 2021, 12:24 last edited by
                              #21

                              @suslucoder said in Selecting multiple files for reading:

                              I want to do such a thing:
                              do some operation
                              for every file that i select

                              so, what's stoping you ?


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              D 1 Reply Last reply 2 Feb 2021, 12:25
                              0
                              • J J.Hilk
                                2 Feb 2021, 12:24

                                @suslucoder said in Selecting multiple files for reading:

                                I want to do such a thing:
                                do some operation
                                for every file that i select

                                so, what's stoping you ?

                                D Offline
                                D Offline
                                deleted286
                                wrote on 2 Feb 2021, 12:25 last edited by
                                #22

                                @J-Hilk I dont know how to do it. Im asking for any idea

                                1 Reply Last reply
                                0
                                • J jsulm
                                  2 Feb 2021, 12:24

                                  @suslucoder Do you really think the order of the two last lines is correct?

                                  D Offline
                                  D Offline
                                  deleted286
                                  wrote on 2 Feb 2021, 12:25 last edited by
                                  #23

                                  @jsulm No you are right

                                  1 Reply Last reply
                                  0

                                  17/23

                                  2 Feb 2021, 12:21

                                  • Login

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