Good morning all,
I am having trouble adding a .PNG file to my Qt Creator project using the QPixmap and QLabel method. The different ways I've tried to do this (in code snippet format) appear below.
System: Raspberry Pi 2 running Debian Wheezy
Builder: Qt Version 4.8.2 For Embedded Linux
Compiler/Tool Chain: 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();
The errors I get with each of these codes when they compile (respectively) are:
code snippet 1:
/home/pi/gpioGUI/main.cpp:187: error: conversion from 'QPixmap*' to non-scalar type 'QPixmap' requested
code snippet 2:
/home/pi/gpioGUI/main.cpp:188: error: no matching function for call to 'QLabel::setPixmap(QPixmap*&)'
candidate is:
void QLabel::setPixmap(const QPixmap&)
note: no known conversion for argument 1 from 'QPixmap*' to 'const QPixmap&'
Thank you very much for any help you can provide.
myLabelPi.setPixmap(myPixmapPi);
tomyLabelPi.setPixmap(*myPixmapPi);
– drescherjmQPixmap
. You could initialize it withQPixmap myPixmap(":/GPIOGUI/rpi2.png");
. – thuga