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
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
cppqt6.6qmlc++
11 Posts 6 Posters 1.3k Views
  • 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
    26 Mar 2024, 01:11

    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
    
    
    P Offline
    P Offline
    Pl45m4
    wrote on 26 Mar 2024, 03:46 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 26 Mar 2024, 04:33
    0
    • P Pl45m4
      26 Mar 2024, 03:46

      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 26 Mar 2024, 04:33 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?

      P J 2 Replies Last reply 26 Mar 2024, 11:51
      0
      • L lvyonghuan
        26 Mar 2024, 04:33

        @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?

        P Offline
        P Offline
        Pl45m4
        wrote on 26 Mar 2024, 11:51 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
          26 Mar 2024, 04:33

          @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?

          J Offline
          J Offline
          JonB
          wrote on 26 Mar 2024, 12:40 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.

          P 1 Reply Last reply 26 Mar 2024, 13:45
          0
          • J JonB
            26 Mar 2024, 12:40

            @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.

            P Offline
            P Offline
            Pl45m4
            wrote on 26 Mar 2024, 13:45 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
              26 Mar 2024, 01:11

              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
              
              
              R Offline
              R Offline
              Ronel_qtmaster
              wrote on 26 Mar 2024, 15:42 last edited by Ronel_qtmaster
              #7

              @lvyonghuan i suspect you have a bad installation of Qt

              C 1 Reply Last reply 26 Mar 2024, 23:59
              0
              • R Ronel_qtmaster
                26 Mar 2024, 15:42

                @lvyonghuan i suspect you have a bad installation of Qt

                C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 26 Mar 2024, 23:59 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

                R 1 Reply Last reply 27 Mar 2024, 05:49
                2
                • C Christian Ehrlicher
                  26 Mar 2024, 23:59

                  @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.

                  R Offline
                  R Offline
                  Ronel_qtmaster
                  wrote on 27 Mar 2024, 05:49 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 27 Mar 2024, 07:16
                  0
                  • R Ronel_qtmaster
                    27 Mar 2024, 05:49

                    @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 27 Mar 2024, 07:16 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.

                    R 1 Reply Last reply 27 Mar 2024, 07:25
                    1
                    • S SimonSchroeder
                      27 Mar 2024, 07:16

                      @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.

                      R Offline
                      R Offline
                      Ronel_qtmaster
                      wrote on 27 Mar 2024, 07:25 last edited by
                      #11

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

                      1 Reply Last reply
                      0

                      11/11

                      27 Mar 2024, 07:25

                      • Login

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