QLabel does not name a type
-
wrote on 25 Mar 2013, 17:11 last edited by
Greetings all,
I'm a total newbie in Qt. I'm trying to add a public attribute to my OMR Class (Main class). The idea is to use this publicly available attribute to access a programatically added QLabel. To do this I added the property in my H file, like this:
@
#ifndef OMR_H
#define OMR_H#include <QMainWindow>
namespace Ui {
class OMR;
}class OMR : public QMainWindow
{
Q_OBJECTpublic:
explicit OMR(QWidget *parent = 0);
QLabel *label_img; // <<< This one
~OMR();private slots:
void on_loadimg_clicked();void on_pushButton_clicked();
private:
Ui::OMR *ui;
};#endif // OMR_H
@
But when I try to compile I get the error: "QLabel does not name a type"
Why does that happen?PS: I'm pretty sure there is a better way to do what I'm trying to do, and if you can, please tell me how. But I also want to know exactly why is QT not allowing me to do it this way.
Thanks in Advance.
-
You are missing #include <QLabel>
It greatly depends on what you are trying to do but it's usually not a good idea to expose "naked pointers" to the ui element. Instead you can make this label private and add some public access methods that have more semantic meaning, eg. displayMessage(Qstring msg) or showCountOfSomething(int value) and then manipulate label directly inside of them.
This is sorta general rule of encapsulation. Outside of main window you shouldn't be concerned with gui types or pointers, but call some well named methods that take care of internals.
-
wrote on 25 Mar 2013, 17:29 last edited by
Geez! that was really stupid! LOL! that fixed the problem. I did try to include QLabel but I did it only on the CPP's. Anyways thanks for your (fast) reply. I'll keep in mind your suggestion.
-
Geez! that was really stupid! LOL! that fixed the problem. I did try to include QLabel but I did it only on the CPP's. Anyways thanks for your (fast) reply. I'll keep in mind your suggestion.
wrote on 4 Jul 2017, 02:59 last edited byThis post is deleted!