Declaring public and slots
-
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? -
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. -
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. -
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? -
@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.htmleven a function its listed as a slot, its a 100% normal c++ member function.
-
@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
-
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. -
@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.
-
@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)