[英]Create video file using sequence of QPixmap in QT Creator- C++
[英]Adding an image file (.PNG) programatically in Qt Creator using QPixmap and QLabel
大家早上好,
我无法使用QPixmap和QLabel方法将.PNG文件添加到Qt Creator项目中。 我尝试执行此操作的不同方式(代码段格式)如下所示。
系统:运行Debian Wheezy的Raspberry Pi 2
生成器:Qt版本4.8.2对于嵌入式Linux
编译器/工具链:GCC / G ++ 4.9.2
code snippet 1
1 #include <QtGui/QApplication>
2 #include <QPixmap>
3 #include <QLabel>
4 #include <wiringPi.h>
5 #include "mainwindow.h"
...
187 QLabel myLabelPi;
188 QPixmap myPixmapPi = new QPixmap(":/GPIOGUI/rpi2.png");
189 myLabelPi.setPixmap(myPixmapPi);
190 myLabelPi.setScaledContents(true);
191 myLabelPi.show();
code snippet 2
1 #include <QtGui/QApplication>
2 #include <QPixmap>
3 #include <QLabel>
4 #include <wiringPi.h>
5 #include "mainwindow.h"
...
187 QLabel myLabelPi;
188 QPixmap *myPixmapPi = new QPixmap(":/GPIOGUI/rpi2.png");
189 myLabelPi.setPixmap(myPixmapPi);
190 myLabelPi.setScaledContents(true);
191 myLabelPi.show();
在编译这些代码时,我分别得到的错误是:
代码段1:
/home/pi/gpioGUI/main.cpp:187:错误:请求从“ QPixmap *”转换为非标量类型“ QPixmap”
代码段2:
/home/pi/gpioGUI/main.cpp:188:错误:没有用于调用'QLabel :: setPixmap(QPixmap *&)'候选对象的匹配函数是:void QLabel :: setPixmap(const QPixmap&)注意:没有已知的转换从'QPixmap *'到'const QPixmap&'的参数1
非常感谢您提供的任何帮助。
仔细阅读错误,大多数时候它包含错误内容。
第188行: new
返回一个指针。 因此,您的变量应该是一个指针(带有*
)
QPixmap* myPixmapPi = new QPixmap(":/GPIOGUI/rpi2.png");
在第189行中,它还说出了什么问题。 您正在传递需要引用的指针。 (虽然我还没有测试代码)
myLabelPi.setPixmap(*myPixmapPi);
试试看,看看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.