jude
jude

Reputation: 31

qclipboard send image to system clipboard

When i try to copy a image into system clipboard(then i can paste it into a ms-word doc),the code below failed,don't know why,even i tried with settext,it also failed.don't know why.

QApplication::clipboard()->setPixmap(
        QPixmap("d://20121001154504.png"),
        QClipboard::Clipboard);

Upvotes: 3

Views: 5380

Answers (2)

Marek R
Marek R

Reputation: 37927

First of all read documentation (use QImage not QPixmap). Then verify that image was loaded properly.

QImage image("d://20121001154504.png");
Q_ASSERT(!image.isNull());
QApplication::clipboard()->setImage(image, QClipboard::Clipboard);

Upvotes: 4

borisbn
borisbn

Reputation: 5054

I tried your code (with my path to picture of course) and has the next result:

When I passed this line by debugger (Step Over or F10 in MSVC), switched to ms-word and tried to paste an image - I got nothing.

When I ran the programm without debugger - I got an appropriate result - an image was pasted in the doc.

#include <QtGui/QApplication>
#include <QClipboard>
#include <QPixmap>

int main( int argc, char * argv[] )
{   
    QApplication a( argc, argv );

    QApplication::clipboard()->setPixmap( QPixmap( "path to my png" ) );
    // if you'll stop here in debugger, you'll have no result

    return a.exec();
}

Upvotes: 1

Related Questions