PDA

View Full Version : Label



hajo93
4th March 2019, 20:31
I want to put in a picture in my QT application.
I made an empty label and called Label_pic
when I go in manwindow.cpp and write
"ui> Label_pic-> setPixmap (pix) for i an error where it says" no member 'label_pic' in 'ui :: mainwindow "1303613037

d_stranz
4th March 2019, 20:37
Your screenshots are too small to read. Please post the ACTUAL CODE, not screenshots so we can read what you are doing. Put your code inside CODE tags (see my signature below).

hajo93
4th March 2019, 20:53
QPixmap pix("C:\QT Nyeveier/Nyeveier.png");
ui->label_Pic->setPixmap(pix)

and then i get this error: no member named 'label_Pic' in 'Ui::MainWindow'


<widget class="QLabel" name="label_Pic">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>151</width>
<height>221</height>
</rect>
</property>
<property name="text">
<string/>
</property>

This is from my mainwindow.ui

tuli
5th March 2019, 07:31
Manually run qmake (rightclick on project -> run qmake) and re-compile the project a few times. Sometimes there are hickups.

d_stranz
5th March 2019, 18:26
Manually run qmake

Yes, I agree. I don't see anything wrong with the code or ui file, and support for "png" format is built-in and does not require a separate driver. So probably your ui file did not get compiled after you added or changed the name of the QLabel item.

Also, make sure when you use a backslash ("") in string that you "escape" it: "C:\\folder\\filename.png" If you don't it will treat a "\f" as a special character and the actual filename string that gets passed to setPixmap() will be incorrect.