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. Declaring public and slots

Declaring public and slots

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.4k 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.
  • B Offline
    B Offline
    BKBK
    wrote on last edited by
    #1

    QT novice.

    The QT assistant installed on our Centos Linux system contains this except from the tutorials code:

    Class Foo
    {
    public:
    int value() const {return val }; // question 1
    public slots: // question 2
    void setValue( int );
    signals:
    void valueChanged( int );
    ...

    Question 1: I don't recognize the meaning of "const" in that position.
    Question 2: What is meant by "slots" following public and before the colon character?

    Gojir4G 1 Reply Last reply
    0
    • B BKBK

      QT novice.

      The QT assistant installed on our Centos Linux system contains this except from the tutorials code:

      Class Foo
      {
      public:
      int value() const {return val }; // question 1
      public slots: // question 2
      void setValue( int );
      signals:
      void valueChanged( int );
      ...

      Question 1: I don't recognize the meaning of "const" in that position.
      Question 2: What is meant by "slots" following public and before the colon character?

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      Hi,
      @BKBK said in Declaring public and slots:

      Question 1: I don't recognize the meaning of "const" in that position.

      It means that this function doesn't make any modification in your class member when you call it. If you try to put val = 1; in the body of the function, you will have an error at compilation.

      @BKBK said in Declaring public and slots:

      Question 2: What is meant by "slots" following public and before the colon character?

      A slot can be connected to a signal to be called when this signal, like valueChanged in your code sample, is "emitted". It's specific to Qt. Please see Qt Signals And Slots.

      1 Reply Last reply
      4
      • B Offline
        B Offline
        BKBK
        wrote on last edited by
        #3

        Regarding Q 1, my example had but one value. I presume the general case in that it means that the function will change no variables. Is that the case? I will further presume that no further reply means yes, that is the case.
        For Q2, I have not found, make that, have not recognized that in the tutorial. I will keep looking and reply again if I cannot find that answer.
        Several people here are using QT but did not know the answers.
        Thanks for the rapid answer.

        VRoninV 1 Reply Last reply
        0
        • B Offline
          B Offline
          BKBK
          wrote on last edited by
          #4

          Oh, I might have it now. The "QT preprocessor" (I just made that up and hope the concept will be clear) will remove the keywords "slot" and "signals" and add appropriate code such that the result is standard C++ code.
          Am I getting at least close?
          Is there a way to edit my posts rather than making a new reply for each comment?

          mrjjM 1 Reply Last reply
          0
          • B BKBK

            Oh, I might have it now. The "QT preprocessor" (I just made that up and hope the concept will be clear) will remove the keywords "slot" and "signals" and add appropriate code such that the result is standard C++ code.
            Am I getting at least close?
            Is there a way to edit my posts rather than making a new reply for each comment?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @BKBK
            Yes, the SLOTS are using by moc.exe tool to
            enumerate all slots listed in that section.
            http://doc.qt.io/qt-5/moc.html
            This is used for signals and slot mechanism
            http://doc.qt.io/qt-5/signalsandslots.html

            even a function its listed as a slot, its a 100% normal c++ member function.

            1 Reply Last reply
            4
            • B BKBK

              Regarding Q 1, my example had but one value. I presume the general case in that it means that the function will change no variables. Is that the case? I will further presume that no further reply means yes, that is the case.
              For Q2, I have not found, make that, have not recognized that in the tutorial. I will keep looking and reply again if I cannot find that answer.
              Several people here are using QT but did not know the answers.
              Thanks for the rapid answer.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @BKBK said in Declaring public and slots:

              I presume the general case in that it means that the function will change no variables.

              Yes but there's so much more to it. Since you are just starting C++ just assume that is true, you'll find out later what other things it means.

              @BKBK said in Declaring public and slots:

              Several people here are using QT but did not know the answers.

              Qt Creator != Qt

              @BKBK said in Declaring public and slots:

              I might have it now. The "QT preprocessor" (I just made that up and hope the concept will be clear) will remove the keywords "slot" and "signals" and add appropriate code such that the result is standard C++ code.

              Bingo!

              Is there a way to edit my posts rather than making a new reply for each comment?

              https://forum.qt.io/topic/71830/hitchhiker-s-visual-guide-to-the-qt-forum You can see the edit button in image #2

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              B 1 Reply Last reply
              4
              • B Offline
                B Offline
                BKBK
                wrote on last edited by
                #7

                cool, I understand the concepts.
                Regarding the edit function: I suspect that my computer is not displaying some icons, such as maybe the ellipsis. This is a government system running IE. Being government we are prime targets for attacks and the firewalls are a bit aggressive.
                Is there a way to insert an image into a message.
                Thanks for the replies, My primary questions are answered so I'll mark as resolved.

                VRoninV 1 Reply Last reply
                0
                • VRoninV VRonin

                  @BKBK said in Declaring public and slots:

                  I presume the general case in that it means that the function will change no variables.

                  Yes but there's so much more to it. Since you are just starting C++ just assume that is true, you'll find out later what other things it means.

                  @BKBK said in Declaring public and slots:

                  Several people here are using QT but did not know the answers.

                  Qt Creator != Qt

                  @BKBK said in Declaring public and slots:

                  I might have it now. The "QT preprocessor" (I just made that up and hope the concept will be clear) will remove the keywords "slot" and "signals" and add appropriate code such that the result is standard C++ code.

                  Bingo!

                  Is there a way to edit my posts rather than making a new reply for each comment?

                  https://forum.qt.io/topic/71830/hitchhiker-s-visual-guide-to-the-qt-forum You can see the edit button in image #2

                  B Offline
                  B Offline
                  BKBK
                  wrote on last edited by
                  #8

                  @VRonin said in Declaring public and slots:

                  @BKBK said in Declaring public and slots:

                  I presume the general case in that it means that the function will change no variables.

                  Yes but there's so much more to it. Since you are just starting C++ just assume that is true, you'll find out later what other things it means.

                  Is there a name for that construct so I can google it?

                  Is there a way to edit my posts rather than making a new reply for each comment?

                  https://forum.qt.io/topic/71830/hitchhiker-s-visual-guide-to-the-qt-forum You can see the edit button in image #2

                  I followed the link but do not see anything that looks like image #2. That supports my weak theory that the firewalls here are blocking stuff. Or maybe IE 11 does not support.

                  1 Reply Last reply
                  0
                  • B BKBK

                    cool, I understand the concepts.
                    Regarding the edit function: I suspect that my computer is not displaying some icons, such as maybe the ellipsis. This is a government system running IE. Being government we are prime targets for attacks and the firewalls are a bit aggressive.
                    Is there a way to insert an image into a message.
                    Thanks for the replies, My primary questions are answered so I'll mark as resolved.

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    @BKBK said in Declaring public and slots:

                    Is there a way to insert an image into a message.

                    Yes, this forum supports Markdown

                    Is there a name for that construct so I can google it?

                    Const methods. If you want to stare in the abyss: https://channel9.msdn.com/posts/C-and-Beyond-2012-Herb-Sutter-You-dont-know-blank-and-blank (I don't expect you to understand what that guy says, he's a big guy in the C++ committee asking questions to expert programmers that they can't answer)

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    2

                    • Login

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