QT自动保存截图带命名模板
QT auto save screenshot with naming template
我想每 10 秒以不同的名称保存多个屏幕截图,
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");
将此功能包装到 class 中。
将静态计数器添加到您的 class(例如 static long long counter {0};
)
声明如下:QString m_path_to_image;
将您的代码更改为
pic.save(path_to_image.arg(m_counter));
您可以将 QString 格式化为您的文件名并在末尾附加一个计数器,如下所示:
int counter = 1;
auto fileName = QString("C:/Users/Coding/Desktop/img/desktop_%1.png").arg(counter);
counter++;
pic.save(fileName);
我想每 10 秒以不同的名称保存多个屏幕截图,
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");
将此功能包装到 class 中。
将静态计数器添加到您的 class(例如 static long long counter {0};
)
声明如下:QString m_path_to_image;
将您的代码更改为
pic.save(path_to_image.arg(m_counter));
您可以将 QString 格式化为您的文件名并在末尾附加一个计数器,如下所示:
int counter = 1;
auto fileName = QString("C:/Users/Coding/Desktop/img/desktop_%1.png").arg(counter);
counter++;
pic.save(fileName);