Get the QPixmap from a QLabel
Get the QPixmap from a QLabel
我有一个名为Picture
的QLabel
,Pixmap
已将其设置为QImage
。
我现在想在另一个函数中修改图像。
是否可以从Picture
获得Pixmap
?
我尝试了以下操作,这会导致未处理的异常:
QPixmap const *pm = ui.Picture->pixmap();
QImage image(pm->toImage());
还有其他办法吗?
我认为您应该检查pixmap()
函数的返回值。
const QPixmap* pixmap = ui.Picture->pixmap();
if ( pixmap )
{
QImage image( pixmap->toImage() );
}
也许您只是在未设置图像时调用该函数,这导致了异常。
相关文章:
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 如何使用新运算符跟踪在循环中创建的 QLabel
- 除了构造函数之外,还创建 QLabel
- std::async from std::async in windows xp
- 在 QLabel 中显示视频
- std::is_reference from std::any
- Qt GUI使用Qfiledialogbox和qlabel显示视频,这是我的代码
- std::time_point from and to std::string
- 如何在C++中将自定义文本设置为 QLabel?
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- std::chrono::time_point from std::string
- 如何使用鼠标单击选择多个 QLabel 对象?
- 在特定时间内更改 QLabel 的背景颜色
- Visual accept std::string from std::byte iterator
- C++中链表的错误"Abort signal from abort(3) (sigabrt) "
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- C++ 中的"template <typename From, typename Tag> struct Alias;"是什么?
- from std::vector to adept::avector
- qt get child (Callout) from QChart
- Get the QPixmap from a QLabel