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. add a numbering to each file
Forum Updated to NodeBB v4.3 + New Features

add a numbering to each file

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 1.2k 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.
  • J jagl

    My problem is simple but I don't see the solution I created a csv file with the date and time which will be saved in a folder my problem I just want to add a numbering to each file by exp:
    when i click in the button for the first time, file name will be: Tab1_2021_07_07_07_33_55
    2nd time will be: Tab2_2021_07_07_07_33_55
    3rd time will be : Tab3_2021_07_07_07_33_55
    code:
    QString filenameTab = QDateTime :: currentDateTime () .toString (QString ("'% 1 / Tab_'yyyy_MM_dd' _ 'hh_mm'.csv"). Arg (folder));

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

    @jagl

    QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm");
    QString folderStr = QString("Tab%1_").arg(folder);
    
    QString filenameTab = folderStr + date + ".csv";
    
    
    

    Then just increase the folder int counter every time you click your button.


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

    ~E. W. Dijkstra

    J 1 Reply Last reply
    1
    • Pl45m4P Pl45m4

      @jagl

      QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm");
      QString folderStr = QString("Tab%1_").arg(folder);
      
      QString filenameTab = folderStr + date + ".csv";
      
      
      

      Then just increase the folder int counter every time you click your button.

      J Offline
      J Offline
      jagl
      wrote on last edited by
      #3

      @Pl45m4 thanks for your reply bu i have this error :device not open

      Pl45m4P 1 Reply Last reply
      0
      • J jagl

        @Pl45m4 thanks for your reply bu i have this error :device not open

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

        @jagl

        That error does not come from your string :)
        How do you open your file?


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

        ~E. W. Dijkstra

        J 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @jagl

          That error does not come from your string :)
          How do you open your file?

          J Offline
          J Offline
          jagl
          wrote on last edited by
          #5

          @Pl45m4
          QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm");
          QString folderStr = QString("Tab%1_").arg(dossier);
          QString filename = folderStr + date + ".csv";
          QFile file(filename);
          if(!file.open(QIODevice::WriteOnly | QIODevice:: Text)) {

          //code
          }

          jsulmJ JonBJ 2 Replies Last reply
          0
          • J jagl

            @Pl45m4
            QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm");
            QString folderStr = QString("Tab%1_").arg(dossier);
            QString filename = folderStr + date + ".csv";
            QFile file(filename);
            if(!file.open(QIODevice::WriteOnly | QIODevice:: Text)) {

            //code
            }

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

            @jagl said in add a numbering to each file:

            file.open

            So, what does open() return?
            And how does filename look like?

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

            J 1 Reply Last reply
            0
            • jsulmJ jsulm

              @jagl said in add a numbering to each file:

              file.open

              So, what does open() return?
              And how does filename look like?

              J Offline
              J Offline
              jagl
              wrote on last edited by jagl
              #7

              @jsulm
              QIODevice::write (QFile, "Tab/root/Desktop/23_2021_07_07_08_40.csv"): device not open
              what does filename look like means ?

              jsulmJ Pl45m4P 2 Replies Last reply
              0
              • J jagl

                @jsulm
                QIODevice::write (QFile, "Tab/root/Desktop/23_2021_07_07_08_40.csv"): device not open
                what does filename look like means ?

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

                @jagl said in add a numbering to each file:

                what does filename look like means ?

                It means: what is the content of filename variable?
                Also, can you please answer this question (asked before already): what does open() return?
                "device not open" means that file was NOT opened.

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

                1 Reply Last reply
                1
                • J jagl

                  @jsulm
                  QIODevice::write (QFile, "Tab/root/Desktop/23_2021_07_07_08_40.csv"): device not open
                  what does filename look like means ?

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

                  @jagl said in add a numbering to each file:

                  Tab/root/Desktop/

                  The content of your dossier variable is not only "Tab" but "Tab/root/Desktop/".

                  Where shoudl your file really be after you create it?
                  Is Tab/root/Desktop/ the file path you want?

                  In your initial post you said, you want a filename like Tab1_2021_07_07_07_33_55, where the "1" in "Tab1" is a variable.


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

                  ~E. W. Dijkstra

                  J 1 Reply Last reply
                  0
                  • Pl45m4P Pl45m4

                    @jagl said in add a numbering to each file:

                    Tab/root/Desktop/

                    The content of your dossier variable is not only "Tab" but "Tab/root/Desktop/".

                    Where shoudl your file really be after you create it?
                    Is Tab/root/Desktop/ the file path you want?

                    In your initial post you said, you want a filename like Tab1_2021_07_07_07_33_55, where the "1" in "Tab1" is a variable.

                    J Offline
                    J Offline
                    jagl
                    wrote on last edited by
                    #10

                    @Pl45m4 yes i want it to be variable thats my question
                    @jsulm
                    the content of filename variable:
                    it is a csv file which contains 4 columns the variables are of type float

                    jsulmJ Pl45m4P 2 Replies Last reply
                    0
                    • J jagl

                      @Pl45m4 yes i want it to be variable thats my question
                      @jsulm
                      the content of filename variable:
                      it is a csv file which contains 4 columns the variables are of type float

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

                      @jagl Could you please read more carefully what others write?
                      I did not ask you what is inside the file, I asked you how the file path you are trying to use looks like! So, QFile file(filename); what is the value of filename?
                      And now I ask for the third (and last) time: what does open() return?

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

                      1 Reply Last reply
                      1
                      • J jagl

                        @Pl45m4 yes i want it to be variable thats my question
                        @jsulm
                        the content of filename variable:
                        it is a csv file which contains 4 columns the variables are of type float

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

                        @jagl said in add a numbering to each file:

                        yes i want it to be variable thats my question

                        I understood that, but what is your desired location for this file? Do you have a folder named "Tab"?

                        My solution writes a file named "Tab[i]_2021_07_07_07_33_55" to your current QDir location.

                        • https://doc.qt.io/qt-5/qdir.html#currentPath

                        If you wish another destination, you need to specify a valid path, which Tab/root/Desktop/ most likely isn't.
                        Do you want something like root/Desktop/Tab/Tab1_2021_07_07_07_33_55.csv?

                        @jagl said in add a numbering to each file:

                        i have this error :device not open

                        @jsulm This comes from file.open, doesn't it? Or rather this error occures because open returned most likely false.


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

                        ~E. W. Dijkstra

                        jsulmJ 1 Reply Last reply
                        0
                        • Pl45m4P Pl45m4

                          @jagl said in add a numbering to each file:

                          yes i want it to be variable thats my question

                          I understood that, but what is your desired location for this file? Do you have a folder named "Tab"?

                          My solution writes a file named "Tab[i]_2021_07_07_07_33_55" to your current QDir location.

                          • https://doc.qt.io/qt-5/qdir.html#currentPath

                          If you wish another destination, you need to specify a valid path, which Tab/root/Desktop/ most likely isn't.
                          Do you want something like root/Desktop/Tab/Tab1_2021_07_07_07_33_55.csv?

                          @jagl said in add a numbering to each file:

                          i have this error :device not open

                          @jsulm This comes from file.open, doesn't it? Or rather this error occures because open returned most likely false.

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

                          @Pl45m4 said in add a numbering to each file:

                          doesn't it?

                          I would say it comes from a write attempt:

                          QIODevice::write (QFile, "Tab/root/Desktop/23_2021_07_07_08_40.csv"): device not open
                          

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

                          Pl45m4P 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Pl45m4 said in add a numbering to each file:

                            doesn't it?

                            I would say it comes from a write attempt:

                            QIODevice::write (QFile, "Tab/root/Desktop/23_2021_07_07_08_40.csv"): device not open
                            
                            Pl45m4P Offline
                            Pl45m4P Offline
                            Pl45m4
                            wrote on last edited by
                            #14

                            @jsulm said in add a numbering to each file:

                            I would say it comes from a write attempt:

                            Ah, yes I see, because the path is no valid writeable location. @jagl messed up the path with the variable.


                            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
                            0
                            • J jagl

                              @Pl45m4
                              QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm");
                              QString folderStr = QString("Tab%1_").arg(dossier);
                              QString filename = folderStr + date + ".csv";
                              QFile file(filename);
                              if(!file.open(QIODevice::WriteOnly | QIODevice:: Text)) {

                              //code
                              }

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

                              @jagl
                              If I copy and paste your code you have

                              if(!file.open(QIODevice::WriteOnly | QIODevice:: Text)) {
                              
                              //code
                              }
                              

                              If you truly test ! file.open() then //code is in the case where it does not open correctly.

                              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