Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. grabWindow always returns null QPixmap
Forum Updated to NodeBB v4.3 + New Features

grabWindow always returns null QPixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpixmapgrab
14 Posts 4 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C ChrisW67

    @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.

    SavizS Offline
    SavizS Offline
    Saviz
    wrote on last edited by
    #3

    @ChrisW67 I only have one monitor and the position that it returns is (0, 0). I also tried your recommendation for just using selectedScreen->grabWindow(), but it still results in a null QPixmap.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zeljko
      wrote on last edited by
      #4

      Try to make screenshoot without timer and check if result is null pixmap.

      SavizS 1 Reply Last reply
      0
      • Z zeljko

        Try to make screenshoot without timer and check if result is null pixmap.

        SavizS Offline
        SavizS Offline
        Saviz
        wrote on last edited by
        #5

        @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.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #6
          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).

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          SavizS 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher
            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).

            SavizS Offline
            SavizS Offline
            Saviz
            wrote on last edited by
            #7

            @Christian-Ehrlicher I noticed you're using QApplication. Could that be the cause of the issue? I'm using QGuiApplication instead because of QML.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #8

              No, tried with a QGuiApplication - all fine.
              Please also test with this minimal example.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              SavizS 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                No, tried with a QGuiApplication - all fine.
                Please also test with this minimal example.

                SavizS Offline
                SavizS Offline
                Saviz
                wrote on last edited by Saviz
                #9

                @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?

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  This is not my code - please test it as I wrote it to make sure the simplest example is working.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  SavizS 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    This is not my code - please test it as I wrote it to make sure the simplest example is working.

                    SavizS Offline
                    SavizS Offline
                    Saviz
                    wrote on last edited by
                    #11

                    @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.

                    1 Reply Last reply
                    0
                    • SavizS Offline
                      SavizS Offline
                      Saviz
                      wrote on last edited by
                      #12

                      Could this be a problem with the version of my Qt kit?

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • SavizS Saviz

                        Could this be a problem with the version of my Qt kit?

                        Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        @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.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          zeljko
                          wrote on last edited by
                          #14

                          Is it under x11 or wayland ?

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved