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. How to take desktop screenshot on Mac OS X?

How to take desktop screenshot on Mac OS X?

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 9.0k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    Ganster41
    wrote on last edited by
    #5

    winId() returns 4317431408.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Ganster41
      wrote on last edited by
      #6

      Hmm, I check this code on Mac OS X 10.8, and it works OK. But on 10.6 it crashes :(

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #7

        If you can, could you build your application directly on 10.6 and retry ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Ganster41
          wrote on last edited by
          #8

          I made all builds on same systems, where made tests. So, it crashes on 10.6 if compiled on 10.6 too.
          I can't find code for taking screenshot in Qt sources, but looks like it uses CGDisplayCreateImage() function. It's buggy on Mac OS 10.6, and crashes app if used. For now I changed code to this, and it works on both Mac OS versions:
          @#ifdef Q_OS_MAC
          // This line crashes app on 10.6, use second instead
          // CGImageRef windowImage = CGDisplayCreateImage(CGMainDisplayID());
          CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionOnScreenOnly,
          0, kCGWindowImageBoundsIgnoreFraming);
          QPixmap screenshot = fromMacCGImageRef(windowImage);
          CGImageRelease(windowImage);
          #else
          QPixmap screenshot = mainScreen->grabWindow(QApplication::desktop()->winId());
          #endif@

          I got fromMacCGImageRef() from old revision of qtmacports.

          But now I got other issue - MyQMainWindow->showFullScreen() does't open window fullscreen. O_o

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Ganster41
            wrote on last edited by
            #9

            I needed to take it from my app. I know how to take it with system hotkeys.
            Now I see some critical bugs in Qt on Mac OS X, so now I trying to use Java.
            Anyway, thanks for the help!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #10

              Can you provide a minimal compilable example that shows the crash ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Ganster41
                wrote on last edited by
                #11

                It's in first post. Just call this code on Mac OS 10.6, and app will crash.
                I can take screenshot with Mac-specific code from my "post":http://qt-project.org/forums/viewreply/150944/ but I got two issues with fullscreen window now:

                1. On 10.6 QMainWindow::showFullScreen() does nothing. Just shows window not fullscreen. Strange, but Java has same issue. Looks like it fixed now with "this":https://codereview.qt-project.org/#change,70543 path, but I didn't try it, because I can't install Qt 5.2 beta to Mac OS 10.6 previosly;
                2. On 10.8 calling QMainWindow::showFullScreen() opens fullscreen window normally, but when I call QMainWindow::close() - blank frame still appears on screen. Don't know how to fix that.
                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vezprog
                  wrote on last edited by
                  #12

                  You can render a QWidget using QPixmap. This is how you would render the QWidget.
                  @
                  // render the widget to QPixmap
                  QPixmap screenshot(widget->size());
                  widget->render(&screenshot);

                  // save the screen shot
                  screenshot.save("fileName.jpg");
                  @

                  Edit: I had to change my post, I misunderstood your question...I thought you wanted to grab a screen shot of the whole screen.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    Ganster41
                    wrote on last edited by
                    #13

                    [quote author="dvez43" date="1387217447"]You might be able to create a transparent widget to the size of the screen (using QDesktopWidget to get the dimensions), and get the screen shot.[/quote]
                    And it really will work on both systems? Looks so hacky.
                    For example, I can't open non-fullscreen window with all screen dimensions. Upper menu bar are unreachable for this windows.

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vezprog
                      wrote on last edited by
                      #14

                      The edited code example above should work.

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        belab
                        wrote on last edited by
                        #15

                        Maybe the problem in your original code is in line 16:
                        @this->screenshot = &screenshot;@
                        You are assigning the pointer of a local object to a member. Going out of scope destroys the pixmap.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          Ganster41
                          wrote on last edited by
                          #16

                          Yes, it was wrong, and I already changed this code. But problem are not here.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #17

                            Did you retry with a more recent version of Qt ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              Ganster41
                              wrote on last edited by
                              #18

                              I no longer have machine with Mac OS 10.6, so I can't test it anymore.
                              Now I trying to support 10.8+ only.

                              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