Hello,

I'm trying to sequentially grab screenshots and send them to a label located on the GUI. The purpose is to eventually write a program which records the screen.

I've successfully achieved this with QPixmap's grabWindow, only it is quite slow and not very framerate friendly (I would love some 20-30fps). I've also noticed that grabWindow hides the mouse before taking a screenshot, which is a great feature usually but doesn't interest me. Also, seeing as it is a QPixmap feature, it is safe to assume that lossless (png?) screenshots are taken, which means 6meg or more per 1080p screen.

Here is my code so far:
Qt Code:
  1. //mw.h
  2. #include <QtGui/QMainWindow>
  3. #include <QApplication>
  4. #include <QPixmap>
  5. #include <QWidget>
  6. #include <QtGui>
  7. #include <QTimer>
  8.  
  9. namespace Ui
  10. {
  11. class mw;
  12. }
  13.  
  14. class mw : public QMainWindow
  15. {
  16. Q_OBJECT
  17.  
  18. public:
  19. mw(QWidget *parent = 0);
  20. ~mw();
  21. QTimer *derp;
  22.  
  23. public slots:
  24. void process();
  25.  
  26. private:
  27. Ui::mw *ui;
  28. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //mw.cpp
  2. using namespace std;
  3.  
  4. mw::mw(QWidget *parent)
  5. : QMainWindow(parent), ui(new Ui::mw)
  6. {
  7. ui->setupUi(this);
  8.  
  9. derp=new QTimer;
  10. connect(derp,SIGNAL(timeout()),this,SLOT(process()));
  11. derp->start(50); //20fps
  12. }
  13.  
  14. mw::~mw()
  15. {
  16. delete ui;
  17. }
  18.  
  19. void mw::process(){
  20. ui->label->setPixmap(QPixmap::grabWindow(QApplication::desktop()->winId()).scaled(ui->label->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
  21. }
To copy to clipboard, switch view to plain text mode 

What would be an alternative to lossless, CPU-intensive screenshots? Would Qt support taking jpg screenshots instead of png? Or perhaps it could be done with OpenGL somehow? Perhaps even QImageWriter?

Thanks in advance.


Regards,
Mr_Cloud