简体   繁体   English

从QLabel获取QPixmap

[英]Get the QPixmap from a QLabel

I have a QLabel called Picture which Pixmap has been set to a QImage . 我有一个名为PictureQLabel ,其中Pixmap已设置为QImage
I now want to modify the image in another function. 我现在想在另一个函数中修改图像。
Is it possible to get the Pixmap from the Picture ? 是否有可能从Picture获取Pixmap

I tried the following, which results in an unhandled exception: 我尝试了以下操作,这会导致未处理的异常:

QPixmap const *pm = ui.Picture->pixmap();  
QImage image(pm->toImage());

Is there any other way? 还有其他方法吗?

I think you shall check the return value of the pixmap() function. 我想你应该检查pixmap()函数的返回值。

const QPixmap* pixmap = ui.Picture->pixmap();
if ( pixmap )
{
    QImage image( pixmap->toImage() );
}

Maybe you just called the function when the image was not set and that caused the exception. 也许你只是在未设置图像时调用该函数并导致异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM