Unsolved Slots/functions in Qt
-
Hi guys, :)
As you probably know (!) I'm coming from C++ programming. There in classes we would define any function inside public or private or protected fields. Is it the same in Qt? That is should I create a function under E.g., public.private slots? What are they for shortly please?
And can a function have no returning type even void? Like:
foo(int n);
-
Hi,
To get you started, you could read the documentation on signals and slots here.
Some relevant information I think is stated as such:"Since slots are normal member functions, they follow the normal C++ rules when called directly. However, as slots, they can be invoked by any component, regardless of its access level, via a signal-slot connection. This means that a signal emitted from an instance of an arbitrary class can cause a private slot to be invoked in an instance of an unrelated class."
-
The detailed info on signals and slots is in the link @calebhalvy posted.
To summarize it shortly: Qt is just a library. It follows all the rules of C++. It doesn't extend the language in any way.
So no, you can't omit the return type from a function. There's no such construct in C++ (well apart from constructor/destructor to be exact).As for the
signals
andslots
- these are just macros used by the code generator (moc) to identify some functions as Qt specific, but it still follows all the rules of C++. Macroslots
expands to nothing so you can make it public, private or protected. Macrosignals
expands topublic
so it doesn't matter what you put before it. -
@calebhalvy said in Slots/functions in Qt:
Thank you for your answer and summarization.@Chris-Kawa said in Slots/functions in Qt:
Thank you very much, especially for your great summarization. :)But I'm annoyed by some word of you! :-( :-(
You typed C++ by a small letter 'c'! C++ is as great as "any language can be, at its highest level". :D :D -
@tomy If these kinds of things annoy you I can't imagine the torture you go through seeing cracks in the pavement every day ;) There. I fixed it.
-
Made C++ great again! ;)
-
@kshegunov Aww, now you made me want to change it back.
-
Just kidding, guys. :) :)