Search code examples
c++qtsavescreenshotautosave

QT auto save screenshot with naming template


I want to save multiple screenshot every 10 second with different name,

i want to save like this

here my current code

      QScreen *screen = QGuiApplication::primaryScreen();
      QPixmap pic  = screen->grabWindow(0);
      pic.save("C:/Users/Coding/Desktop/img/desktop_1.png");

Solution

  • You can format a QString to your file name and append a counter at the end, like this:

    int counter = 1;
    auto fileName = QString("C:/Users/Coding/Desktop/img/desktop_%1.png").arg(counter);
    counter++;
    pic.save(fileName);