[Qt-interest] Grab the desktop on Mac

Irfan Omair irfan.omair.qt at gmail.com
Fri Aug 6 19:47:11 CEST 2010


can you also try QPixmap QPixmap::grabWidget ()

I doubut even this will work?

Regards,
Irfan Omair
Qt Developer

On Fri, Aug 6, 2010 at 10:45 AM, Irfan Omair <irfan.omair.qt at gmail.com>wrote:

> This is surprizing, as this works great for me.
>
> If you are doing a lot of things in the application before you are
> taking the screen shot, you could try to call
> QApplication::processEvents() to clear out any events before you try to
> capture the screen.
>
> Is there some way to verify that the value returned by
> FmApplication::desktop()->winId() is valid?
> can you try this example and see if this works for you.
> #include <QtGui>
> class MyWidget: public QWidget
> {
>     Q_OBJECT
>
> public:
>     MyWidget(QWidget *parent = 0);
>
> private slots:
>    void doSomething();
>
> private:
>     QHBoxLayout *layout;
>     QPushButton *button;
> };
> MyWidget::MyWidget(QWidget *parent)
> : QWidget(parent)
> {
>     setWindowTitle("Support Tester");
>     layout = new QHBoxLayout;
>     button = new QPushButton ("Do Something");
>     layout->addWidget(button);
>
>     setLayout(layout);
>
>     QObject::connect(button, SIGNAL(clicked()),
>                      this, SLOT(doSomething()));
> }
> void MyWidget::doSomething()
> {
>     qDebug("something clicked");
>
>        QPixmap  the_pixmap1 =
> QPixmap::grabWindow(QApplication::desktop()->winId());
>       the_pixmap1.save("test1.png");
>     //
>        QPixmap the_pixmap = QPixmap::grabWidget(QApplication::desktop());
>         the_pixmap.save("test2.png");
>
> }
> #include "main.moc"
> int main(int argc, char *argv[])
> {
>     QApplication app(argc, argv);
>     MyWidget *myWin = new MyWidget();
>     myWin->show();
>     return app.exec();
> }
>
>
>   On Fri, Aug 6, 2010 at 9:01 AM, simion ploscariu <simion314 at gmail.com>wrote:
>
>> Hi, i am trying to grab a pixmap with the desktop on Mac
>>  QPixmap pixmap= QPixmap::grabWindow(QApplication::desktop()->winId());;
>>    if(pixmap.isNull())
>>    {
>>        qDebug("QPixmap::grabWindow(QApplication::desktop()->winId());;
>>  -returned a null image");
>>    }
>>
>> and the pixmap is null.
>> Any idea? Thx
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100806/161cecd9/attachment.html 


More information about the Qt-interest-old mailing list