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. Capture screenshot not working (Qt 5.4) Linux Yocto
Forum Updated to NodeBB v4.3 + New Features

Capture screenshot not working (Qt 5.4) Linux Yocto

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.9k 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
    gmahan
    wrote on last edited by
    #1

    Hi,

    I'm trying to capture a screenshot in PNG of my device that is running a custom Yocto linux build. When I run the application I get no value in the byteArray that contains the image. The code works fine on my Fedora Linux workstation.

    The code is as follows:

    @void Utils::GetScreenBase64String(QByteArray &bArray)
    {

    QScreen *screen = QGuiApplication::primaryScreen();
    
    if (screen)
    {
        QPixmap pixmap = QPixmap(); // Create a new pixmap
        pixmap = screen->grabWindow(0); // Grab the screenshot
    
        bArray.clear(); // Clear the byte array
    
        QBuffer buffer(&bArray);
    
        buffer.open(QIODevice::WriteOnly);
        pixmap.save(&buffer, "PNG");
        buffer.close();
    
        bArray = bArray.toBase64();
    }
    

    }@

    I have also tried the following :

    @void Utils::GetScreenBase64String(QByteArray &bArray)
    {

    QScreen *screen = QGuiApplication::primaryScreen();
    
    if (screen)
    {
        QWindow window;
        QPixmap pixmap = QPixmap(); // Create a new pixmap
        pixmap = screen->grabWindow(window.winId()); // Grab the screenshot
    
        bArray.clear(); // Clear the byte array
    
        QBuffer buffer(&bArray);
    
        buffer.open(QIODevice::WriteOnly);
        pixmap.save(&buffer, "PNG");
        buffer.close();
    
        bArray = bArray.toBase64();
    }
    

    }@

    bArray in both cases is returned empty. Not sure if I am missing some kernel library. Any help would be appreciated.

    Thanks!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      agocs
      wrote on last edited by
      #2

      QScreen::grabWindow is useless when not running on an actual windowing system. On embedded it is simply not implemented.

      For Qt Quick apps, use QQuickWindow::grabWindow() instead.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gmahan
        wrote on last edited by
        #3

        Thanks for replying to this. I added the QQuickWindow module to the file and to the .pro (quick) file. But I now run into the following issue on compile time:

        /home/gmahan/Qt5.4.0/5.4/gcc_64/include/QtGui/qopengl.h:122: error: GL/gl.h: No such file or directory

        include <GL/gl.h>

                         ^
        

        Not sure what's causing this. Sorry, I'm relatively new to Qt.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          agocs
          wrote on last edited by
          #4

          Hmm you are missing OpenGL support. Then your apps are QWidget-based, I guess? In that case try something like http://doc-snapshot.qt-project.org/qt5-5.4/qwidget.html#render

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gmahan
            wrote on last edited by
            #5

            I changed the function to use QWidget.render(), but all I get is a blank screen as the image.

            @void Utils::GetScreenBase64String(QByteArray &bArray, QWidget *widget)
            {

            QScreen *screen = QGuiApplication::primaryScreen();
            
            if (screen)
            {
                QPixmap pixmap(widget->size()); // Create a new pixmap
                widget->render(&pixmap);
            
                //pixmap = screen->grabWindow(WindowId::GetCurrentWinId()); // Grab the screenshot
            
                bArray.clear(); // Clear the byte array
            
                QBuffer buffer(&bArray);
            
                buffer.open(QIODevice::WriteOnly);
                pixmap.save(&buffer, "PNG");
                buffer.close();
            
                bArray = bArray.toBase64();
            }
            

            }
            @

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

              The above code worked fine on my workstation running Linux, I was not capturing the entire base64 string when trying to decode. I need to run on my embedded device to see if it works fine.

              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