Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel does not name a type
Forum Updated to NodeBB v4.3 + New Features

QLabel does not name a type

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 12.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FjjF
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        FjjF
        wrote on last edited by
        #3

        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.

        J 1 Reply Last reply
        0
        • F FjjF

          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.

          J Offline
          J Offline
          Johnforace
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved