qclipboard send image to system clipboard

杀马特。学长 韩版系。学妹 提交于 2019-12-11 02:55:07

问题


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);

回答1:


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);



回答2:


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();
}


来源:https://stackoverflow.com/questions/14360201/qclipboard-send-image-to-system-clipboard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!