Solved How to match different paras for signal and slots using new functional-style "connect"?
-
Hello !
In Qt4, we know that we can connect a signal which have more parameters than a slot :connect(timer, SIGNAL(timeout()), widget, SLOT(update()));
timer is a QTimer object pointer, and widget is a QWidget.
However , it seems that new functional style connect requires signal and slot functions have same parameters table.
connect (timer, &QTimer::timeout, widget, &MyWidget::update);
The code above fired a compiler error, that is caused by Exact Match Parameter Table.
Question1:
For qt5 new functional style connect, how to deal with function overload and different paras connection?
Question2:
Will old style connect (using marco) be supported in future?Thanks!
-
@goldenhawking Hi,friend. Welcome.
You can see this thread About signal and slots in Qt4 and Qt5.
If I remember correctly, you should be a Chinese teacher. So, i find Chinese blog from cnblog for you. cnblog Qt Signal and slot.
End, if you want to get more information, you could search
signal and slot
in Qt help manual. -
@joeQ said in How to match different paras for signal and slots using new functional-style "connect"?:
cnblog
thanks!
-
Will old style connect (using marco) be supported in future?
Maybe in some distant future it will be removed
but it will break heaps of code so i be surprised
if they removed anytime soon.But it would make porting 4.X code to 5.X extra complicated so
i really doubt it will be removed in this decade.The real benefit of the new syntax is that it fails at compile time and not
runtime.
Also Docs saysConnecting C++ Objects to QML Objects The string-based syntax can connect C++ objects to QML objects, but the functor-based syntax cannot.
So that give me some reassurance as long as widgets exists.
-
@mrjj said in How to match different paras for signal and slots using new functional-style "connect"?:
ome rea
Thank you very much of these answers!