grabWindow always returns null QPixmap
-
@zeljko I tried your suggestion and called it without the timer part for both versions like this:
Version 1:
QPixmap output = selectedScreen->grabWindow(0, selectedScreen->geometry().x(), selectedScreen->geometry().y(), selectedScreen->geometry().width(), selectedScreen->geometry().height()); if (output.isNull()) { qDebug() << "Pixmap is null."; }
Version 2:
QPixmap output = selectedScreen->grabWindow(); if (output.isNull()) { qDebug() << "Pixmap is null."; }
Both result in a null QPixmap.
-
int main(int argc, char* argv[]) { QApplication a(argc, argv); auto pm = a.primaryScreen()->grabWindow(); qDebug() << pm; return 0; }
This works fine for me with Qt6.8 on windows 10 and linux (x11).
-
@Christian-Ehrlicher I noticed you're using
QApplication
. Could that be the cause of the issue? I'm usingQGuiApplication
instead because of QML. -
No, tried with a QGuiApplication - all fine.
Please also test with this minimal example. -
@Christian-Ehrlicher I created a new project using the simple example you provided and tested it on each platform. Here is the complete code:
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; // Loading engine here... auto pm = app.primaryScreen()->grabWindow(); qDebug() << pm; return app.exec() }
I did a bunch of tests. It was only successful in one run, and every other time the output is still null. At this point, I'm not sure what might be causing the problem as the results flicker. Could it be related to the Qt version?
-
This is not my code - please test it as I wrote it to make sure the simplest example is working.
-
@Christian-Ehrlicher I even tested your code using QApplication
int main(int argc, char* argv[]) { QApplication a(argc, argv); auto pm = a.primaryScreen()->grabWindow(); qDebug() << pm; return 0; }
This results in the same issues.
@Christian-Ehrlicher said in grabWindow always returns null QPixmap:
No, tried with a QGuiApplication - all fine.
Please also test with this minimal example.Besides, what difference does it make? You were the one who claimed there was no difference.
-
@Saviz said in grabWindow always returns null QPixmap:
Could this be a problem with the version of my Qt kit?
I don't think so. It works for sure on windows - the rest depends on the window manager.