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
QtWS25 Last Chance

grabWindow always returns null QPixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpixmapgrab
14 Posts 4 Posters 1.0k 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.
  • 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 Offline
      Christian EhrlicherC Offline
      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 Offline
          Christian EhrlicherC Offline
          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 Offline
              Christian EhrlicherC Offline
              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 Offline
                    Christian EhrlicherC Offline
                    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