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. ‘signals’ and 'public slots' does not name a type
Forum Updated to NodeBB v4.3 + New Features

‘signals’ and 'public slots' does not name a type

Scheduled Pinned Locked Moved Unsolved General and Desktop
cppqt6.6qmlc++
11 Posts 6 Posters 1.6k Views 2 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.
  • L lvyonghuan

    I recently started using QT for project needs. QML and CPP are required to perform docking operations.But when I used the two tags signals and public slots, I found that the IDE did not use them as keywords, and the compilation could not pass.I double checked and it does inherit from QObject.I don't know what to do, can anyone help me?
    The following is the source code:

    #ifndef PLUGINLIST_H
    #define PLUGINLIST_H
    
    #include <QObject>
    
    class PluginList : public QObject
    {
        Q_OBJECT
    
        Q_PROPERTY(int pluginCount READ pluginCount NOTIFY pluginCountChanged)
    
    public:
        explicit PluginList(QObject *parent = nullptr)
            : QObject(parent), m_pluginCount(0) {} // 初始化 m_pluginCount 为 0
        int pluginCount() const {
            return m_pluginCount;
        }
    
    public slots:
        void setPluginCount(int count) {
                m_pluginCount = count; // 更新 pluginCount 属性的值
                emit pluginCountChanged(); // 发射 pluginCountChanged 信号,通知属性的变化
        }
    
    signals:
        void pluginCountChanged();
    
    private:
        int m_pluginCount;
    };
    
    #endif // PLUGINLIST_H
    
    
    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #2

    Hi @lvyonghuan ,

    try Q_SIGNALS / Q_SIGNAL and Q_SLOT / Q_SLOTS if your IDE/compiler has issues recognizing the keywords.


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    L 1 Reply Last reply
    0
    • Pl45m4P Pl45m4

      Hi @lvyonghuan ,

      try Q_SIGNALS / Q_SIGNAL and Q_SLOT / Q_SLOTS if your IDE/compiler has issues recognizing the keywords.

      L Offline
      L Offline
      lvyonghuan
      wrote on last edited by lvyonghuan
      #3

      @Pl45m4 Thanks, I'll try it.
      By the way, I still find it strange that I use QT creator as the IDE. Even if there is a problem with the IDE, the compilation should be normal. But it also reports an error when compiling.


      It works. Has the keyword signals been deprecated in the new version?

      Pl45m4P JonBJ 2 Replies Last reply
      0
      • L lvyonghuan

        @Pl45m4 Thanks, I'll try it.
        By the way, I still find it strange that I use QT creator as the IDE. Even if there is a problem with the IDE, the compilation should be normal. But it also reports an error when compiling.


        It works. Has the keyword signals been deprecated in the new version?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #4

        @lvyonghuan said in ‘signals’ and 'public slots' does not name a type:

        Has the keyword signals been deprecated in the new version?

        Not that I know of... in QtCreator with Qt6.6 that should still work.
        The main purpose to use the "other" macros is, when you have multiple thirdparty libraries and they all have their own kinda "signals". So you can clearly differentiate between them and they are not ambiguous anymore.
        Is it a compiler error/warning or is just the code model complaining?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • L lvyonghuan

          @Pl45m4 Thanks, I'll try it.
          By the way, I still find it strange that I use QT creator as the IDE. Even if there is a problem with the IDE, the compilation should be normal. But it also reports an error when compiling.


          It works. Has the keyword signals been deprecated in the new version?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #5

          @lvyonghuan
          Normally from Qt signals is a macro expanding to public and slots is a macro expanding to empty. moc recognizes them to do its work, but the compiler should see the macros. So the compiler at least should not report ‘signals’ and 'public slots' does not name a type. Unless something has #undefed them. Which is the only way I can guess you find Q_SIGNALS etc. are required. So not sure what is going on in your case.

          Pl45m4P 1 Reply Last reply
          0
          • JonBJ JonB

            @lvyonghuan
            Normally from Qt signals is a macro expanding to public and slots is a macro expanding to empty. moc recognizes them to do its work, but the compiler should see the macros. So the compiler at least should not report ‘signals’ and 'public slots' does not name a type. Unless something has #undefed them. Which is the only way I can guess you find Q_SIGNALS etc. are required. So not sure what is going on in your case.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #6

            @JonB said in ‘signals’ and 'public slots' does not name a type:

            Unless something has #undefed them

            For instance using the no_keywords flag :)
            This would explain why Q_SLOTS works. But I don't know why you would do this directly when starting with Qt


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            2
            • L lvyonghuan

              I recently started using QT for project needs. QML and CPP are required to perform docking operations.But when I used the two tags signals and public slots, I found that the IDE did not use them as keywords, and the compilation could not pass.I double checked and it does inherit from QObject.I don't know what to do, can anyone help me?
              The following is the source code:

              #ifndef PLUGINLIST_H
              #define PLUGINLIST_H
              
              #include <QObject>
              
              class PluginList : public QObject
              {
                  Q_OBJECT
              
                  Q_PROPERTY(int pluginCount READ pluginCount NOTIFY pluginCountChanged)
              
              public:
                  explicit PluginList(QObject *parent = nullptr)
                      : QObject(parent), m_pluginCount(0) {} // 初始化 m_pluginCount 为 0
                  int pluginCount() const {
                      return m_pluginCount;
                  }
              
              public slots:
                  void setPluginCount(int count) {
                          m_pluginCount = count; // 更新 pluginCount 属性的值
                          emit pluginCountChanged(); // 发射 pluginCountChanged 信号,通知属性的变化
                  }
              
              signals:
                  void pluginCountChanged();
              
              private:
                  int m_pluginCount;
              };
              
              #endif // PLUGINLIST_H
              
              
              Ronel_qtmasterR Offline
              Ronel_qtmasterR Offline
              Ronel_qtmaster
              wrote on last edited by Ronel_qtmaster
              #7

              @lvyonghuan i suspect you have a bad installation of Qt

              Christian EhrlicherC 1 Reply Last reply
              0
              • Ronel_qtmasterR Ronel_qtmaster

                @lvyonghuan i suspect you have a bad installation of Qt

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #8

                @Ronel_qtmaster said in ‘signals’ and 'public slots' does not name a type:

                i suspect you have a bad installation of Qt

                Why? Just because no_keywords is set as @Pl45m4 pointed out? Don't simply write stuff due to wild unsolicited guesses.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                Ronel_qtmasterR 1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  @Ronel_qtmaster said in ‘signals’ and 'public slots' does not name a type:

                  i suspect you have a bad installation of Qt

                  Why? Just because no_keywords is set as @Pl45m4 pointed out? Don't simply write stuff due to wild unsolicited guesses.

                  Ronel_qtmasterR Offline
                  Ronel_qtmasterR Offline
                  Ronel_qtmaster
                  wrote on last edited by
                  #9

                  @Christian-Ehrlicher Maybe i am wrong but as far as i know signal and slots mechanism is the basis of
                  event management programming of Qt-based applications.If they're not recognized by the moc what can this means according to you?It is not even normal that a simple qt installation does not recognize it

                  S 1 Reply Last reply
                  0
                  • Ronel_qtmasterR Ronel_qtmaster

                    @Christian-Ehrlicher Maybe i am wrong but as far as i know signal and slots mechanism is the basis of
                    event management programming of Qt-based applications.If they're not recognized by the moc what can this means according to you?It is not even normal that a simple qt installation does not recognize it

                    S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #10

                    @Ronel_qtmaster said in ‘signals’ and 'public slots' does not name a type:

                    If they're not recognized by the moc what can this means according to you?

                    If you have compiler errors it is not moc. moc most likely recognizes the keywords just fine. Most likely it is some project setting that turns off the keywords for the compiler. Then it's not your Qt installation that is messed up.

                    Ronel_qtmasterR 1 Reply Last reply
                    1
                    • S SimonSchroeder

                      @Ronel_qtmaster said in ‘signals’ and 'public slots' does not name a type:

                      If they're not recognized by the moc what can this means according to you?

                      If you have compiler errors it is not moc. moc most likely recognizes the keywords just fine. Most likely it is some project setting that turns off the keywords for the compiler. Then it's not your Qt installation that is messed up.

                      Ronel_qtmasterR Offline
                      Ronel_qtmasterR Offline
                      Ronel_qtmaster
                      wrote on last edited by
                      #11

                      @SimonSchroeder OKay thanks.We shall see when he explain more

                      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