grabWindow always returns null QPixmap
-
@Saviz said in grabWindow always returns null QPixmap:
// The geomotry is correct and gives 1920 X 1080
What does it give for the position and are you in a single or multi-monitor setup? In multi-monitor, some of the screens will return a non-zero position (e.g. 1920x1080+1920+0) and, because the x/y parameters to grabWindow() are relative to the screen, using these values will place the capture area outside the screen.
Have you tried without the geometry? This,
selectedScreen->grabWindow()
, should default to grabbing all of the screen. -
@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.