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. How to increment Image name ?
Qt 6.11 is out! See what's new in the release blog

How to increment Image name ?

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 5 Posters 3.9k 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.
  • KroMignonK KroMignon

    @hamzaelazizi said in How to increment Image name ?:

    i've tried multiple approaches but none of them worked! :(

    I don't know how you are generating the ID, if it is a free running counter why not use the modulo function?

    QString fileName = QString("%1.png").arg(1 + (id % 11));
    
    hamzaelaziziH Offline
    hamzaelaziziH Offline
    hamzaelazizi
    wrote on last edited by
    #12

    @KroMignon I wanted to use it, in fact i was trying it over and over but since i'm new to Qt i didn't know how to get it to work :( (i feel ashamed now), when i tried your solution, it seems like it's working! i don't know if i will be running into some issues in the futur, but i guess that would be a problem for another day, Thank you

    1 Reply Last reply
    0
    • KroMignonK KroMignon

      @jsulm said in How to increment Image name ?:

      The id is comming from https://doc.qt.io/qt-5/qcameraimagecapture.html#imageCaptured

      I see! :D

      So this would also not work!
      Then I don't see another solution as what @jsulm already suggested: use class member to store the counter value

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

      @KroMignon said in How to increment Image name ?:

      So this would also not work!

      Actually it should :-)

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

      KroMignonK 1 Reply Last reply
      0
      • jsulmJ jsulm

        @KroMignon said in How to increment Image name ?:

        So this would also not work!

        Actually it should :-)

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #14

        @jsulm said in How to increment Image name ?:

        Actually it should :-)

        Okay, I never used QCameraImageCapture, so I supposed the ID would be the ID of the used camera and not if the image...
        Maybe I should avoid the reply to posts for topics I not experimented in!

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        hamzaelaziziH 1 Reply Last reply
        0
        • KroMignonK KroMignon

          @jsulm said in How to increment Image name ?:

          Actually it should :-)

          Okay, I never used QCameraImageCapture, so I supposed the ID would be the ID of the used camera and not if the image...
          Maybe I should avoid the reply to posts for topics I not experimented in!

          hamzaelaziziH Offline
          hamzaelaziziH Offline
          hamzaelazizi
          wrote on last edited by
          #15

          @KroMignon Sir, your solution helped me, so i think you should keep relying to this kind of posts :D, i have one last question, @jsulm how can i use my own id variable ? should i create a variable inside this class ? i don't understand !

          jsulmJ 1 Reply Last reply
          0
          • hamzaelaziziH hamzaelazizi

            @KroMignon Sir, your solution helped me, so i think you should keep relying to this kind of posts :D, i have one last question, @jsulm how can i use my own id variable ? should i create a variable inside this class ? i don't understand !

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

            @hamzaelazizi said in How to increment Image name ?:

            should i create a variable inside this class ?

            Yes and you initialize it with 0. Each time your slot is called you increment it and check whether it is bigger than the max id value you want to use, if it is you set it back to 0.

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

            hamzaelaziziH 1 Reply Last reply
            0
            • jsulmJ jsulm

              @hamzaelazizi said in How to increment Image name ?:

              should i create a variable inside this class ?

              Yes and you initialize it with 0. Each time your slot is called you increment it and check whether it is bigger than the max id value you want to use, if it is you set it back to 0.

              hamzaelaziziH Offline
              hamzaelaziziH Offline
              hamzaelazizi
              wrote on last edited by
              #17

              @jsulm something like this ?

              
              QObject::connect(_image_capture.data(), &QCameraImageCapture::imageCaptured, [=] (int id=0, QImage img) {
               int idx = 0;
               if(idx>=11)
               {
                       idx=0;
               }
               else
               {
                       idx++;
               }
                QString fileName = QString::number(idx) + ".png";
                QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + fileName;
                img.save(path, "PNG");
                          });
              

              Because i've tried this and it didn't work :/

              jsulmJ Cobra91151C 2 Replies Last reply
              0
              • hamzaelaziziH hamzaelazizi

                @jsulm something like this ?

                
                QObject::connect(_image_capture.data(), &QCameraImageCapture::imageCaptured, [=] (int id=0, QImage img) {
                 int idx = 0;
                 if(idx>=11)
                 {
                         idx=0;
                 }
                 else
                 {
                         idx++;
                 }
                  QString fileName = QString::number(idx) + ".png";
                  QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + fileName;
                  img.save(path, "PNG");
                            });
                

                Because i've tried this and it didn't work :/

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

                @hamzaelazizi said in How to increment Image name ?:

                something like this ?

                No.
                In your code idx is a local variable and not a class member...

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

                hamzaelaziziH 1 Reply Last reply
                0
                • hamzaelaziziH hamzaelazizi

                  @jsulm something like this ?

                  
                  QObject::connect(_image_capture.data(), &QCameraImageCapture::imageCaptured, [=] (int id=0, QImage img) {
                   int idx = 0;
                   if(idx>=11)
                   {
                           idx=0;
                   }
                   else
                   {
                           idx++;
                   }
                    QString fileName = QString::number(idx) + ".png";
                    QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + fileName;
                    img.save(path, "PNG");
                              });
                  

                  Because i've tried this and it didn't work :/

                  Cobra91151C Offline
                  Cobra91151C Offline
                  Cobra91151
                  wrote on last edited by
                  #19

                  @hamzaelazizi

                  I have updated my previous post. Please, try it again.

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @hamzaelazizi said in How to increment Image name ?:

                    something like this ?

                    No.
                    In your code idx is a local variable and not a class member...

                    hamzaelaziziH Offline
                    hamzaelaziziH Offline
                    hamzaelazizi
                    wrote on last edited by
                    #20

                    @jsulm i see, but whenever i declare a variable outside the method i get this error saying that the variable i created is a Read-only

                    JonBJ jsulmJ 2 Replies Last reply
                    0
                    • hamzaelaziziH hamzaelazizi

                      @jsulm i see, but whenever i declare a variable outside the method i get this error saying that the variable i created is a Read-only

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

                      @hamzaelazizi Depends what you write and where.

                      1 Reply Last reply
                      0
                      • hamzaelaziziH hamzaelazizi

                        @jsulm i see, but whenever i declare a variable outside the method i get this error saying that the variable i created is a Read-only

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

                        @hamzaelazizi said in How to increment Image name ?:

                        outside the method

                        I never suggested to declare it outside of the method. I suggested to declare it as a class member:

                        class YOUR_CLASS:
                        {
                        private:
                            int idx{0};
                        

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

                        hamzaelaziziH 1 Reply Last reply
                        2
                        • jsulmJ jsulm

                          @hamzaelazizi said in How to increment Image name ?:

                          outside the method

                          I never suggested to declare it outside of the method. I suggested to declare it as a class member:

                          class YOUR_CLASS:
                          {
                          private:
                              int idx{0};
                          
                          hamzaelaziziH Offline
                          hamzaelaziziH Offline
                          hamzaelazizi
                          wrote on last edited by
                          #23

                          @jsulm i understand now, thank you for your explanation

                          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