Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QLabel does not name a type

    General and Desktop
    3
    4
    12113
    Loading More Posts
    • 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
      FjjF 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_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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 0
        • F
          FjjF 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.

          J 1 Reply Last reply Reply Quote 0
          • J
            Johnforace @FjjF last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • First post
              Last post