Hello.
Please excuse me for my poor english.
I am trying to write a program, and one of its functions will be manipulations with windowses of other programs.
In particular, moving them and making its screenshots.
I am trying to make screenshot with code like this one:
for (const auto& screen : QGuiApplication::screens()) {
if (screen) {
QPixmap screenshot
= screen
->grabWindow
(window_id
);
if (!screenshot.isNull() && screenshot.save("screenshot.png")) {
cout << "saved" << endl;
}
}
}
for (const auto& screen : QGuiApplication::screens()) {
if (screen) {
QPixmap screenshot = screen->grabWindow(window_id);
if (!screenshot.isNull() && screenshot.save("screenshot.png")) {
cout << "saved" << endl;
}
}
}
To copy to clipboard, switch view to plain text mode
However, to make it work, I have to create a Q*Application object:
QApplication a(argc, argv);
To copy to clipboard, switch view to plain text mode
Without it, nothing works (QGuiApplication::screens() is empty).
In case where a program activelu uses Qt it is not a problem.
However, I am trying to make a small library, which can manipulate with windovs via qt, and use the library in my program.
So I want to make my program qt-independent (with exception of the manipulating library ofc).
In this case making global object of a qt type is looking bad.
So what is correct way to solve the task?
Make a singleton with QApplication inside the library?
Bookmarks