Unsolved Connect Prototype help
-
@jsulm , thank you. Is there an implementation of the connect that will allow this signal syntax with a lambda slot?
-
@SPlatten https://doc.qt.io/qt-5/qobject.html
Only with the new connect syntax. -
@jsulm , thats what I thought, so back to the requirement, can I roll my own and create a connect which does exactly what I required?
Is there a way to translate the SIGNAL(signal) into the new syntax?
-
So the penny has dropped now, I've been working with C since the mid 80's and C++ since the early 90's. The language has changed quite a lot over the years and there are elements of the language that I have never had to use, however with the introduction of some of the newer enhancements its time to learn and adopt some of these features.
Specifically templates, I've used them when developing Qt applications without really paying to much attention. Now I find its an absolute requirement if I'm to implement the kind of features I want in my application.
I want to be able to support any signal that a Qt widget has and connect ever signal to the same Lambda slot, this is going to require some cool code and I know it's possible as thats exactly what the standard connect does.
I'm currently working through online tutorials, any help or input is greatly appreciated.
-
Hi,
Depending on your goal with that, did you consider using some meta object programming ?
-
@SGaist , please tell me more...
-
It's all in the link ;-)
The idea is that you can use introspection of your QObject based classes. You can get all the signals of your class, or go upper the chain and get the signals of the base classe (for as many class as your hierarchy has). Then you can use the various QMetaXXX classes to do what you want.
-
Ok, to summarise, what I want to do is reduce all signal and slot connections to a single connect call and then manage the details of the signal in the lambda slot.
-
You can't have only one connect statement. However with the introspection, you can loop on the signals to connect them to the same lambda.
However there's one issue that you are going to have: signals will have different parameters, how are you going to manage that in your lambda ?
-
@SGaist , sorry thats really what I meant, I would have a single map in my application where my derived Qt control classes register they're signals and then that map will be processed after reading the configuration from XML files where the subscribers will be defined. The subscribers (slots) will be connected to the signals using a common function. From what I've seen so far, having different parameters isn't a problem.
-
Some sort of configurable pub/sub design ?
-
@SGaist , absolutely, everything I'm working towards will take Qt into a new era, where once the engine is complete, you will only need to have the same engine for each platform you want to run on, but the actual application will be a series of XML files and JavaScript files.
-
Then you will have to go with introspection.
-