[Development] Enum classes in signals?
Alexander Nassian
nassian at bitshift-dynamics.com
Wed Feb 6 10:00:58 CET 2019
That’s why it is always good practice to only use FQTN in public headers anyway ;)
Beste Grüße / Best regards,
Alexander Nassian
> Am 06.02.2019 um 05:41 schrieb Giuseppe D'Angelo via Development <development at qt-project.org>:
>
> Il 05/02/19 18:16, Dmitriy Purgin ha scritto:
>> I couldn't figure out the exact combination but as far as I remember, if you have namespaced code, you have to always fully qualify the enum class parameters in signals and slots.
>
> This is actually also the case for enums and enum classes. For instance, consider
>
> class A : public QObject {
> Q_OBJECT
> public:
> enum class E { E1, E2, E3 };
> signals:
> void mySignal(E);
> };
>
> class B : public QObject {
> Q_OBJECT
> public slots:
> void mySlot(A::E);
> };
>
> This code compiles just fine, but you will NOT be able to connect mySignal1 to mySlot using SIGNAL/SLOT.
>
> Doing it like this
>
> connect(a, SIGNAL(mySignal(E)), b, SLOT(mySlot(A::E)));
>
> won't work because the argument lists don't match (this connect version compares the parameter lists _as strings_, and obviously "E" is different from "A::E").
>
>
> Connecting it like this
>
> connect(a, SIGNAL(mySignal(A::E)), b, SLOT(mySlot(A::E)));
>
> will not find mySignal in A, because the lookup will search for a function with that signature _spelled exactly that way in the source code_. Such a function is not there; the source code spells "E" as parameter type, not "A::E".
>
> The solution hence is to declare the signal with an A::E parameter.
>
> My 2 c,
> --
> Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
> KDAB (France) S.A.S., a KDAB Group company
> Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
> KDAB - The Qt, C++ and OpenGL Experts
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development
--
—
bitshift dynamics GmbH
Neudorfer Str. 1, 79541 Lörrach
Registergericht: Amtsgericht Freiburg i. Breisgau, HRB 713747
Geschäftsführer: Alexander Nassian, Markus Pfaffinger
http://www.bitshift-dynamics.de <http://www.bitshift-dynamics.de/>
Zentrale: +49 762158673 - 0
Fax: +49 7621 58673 - 90
Allgemeine Anfragen:
info at bitshift-dynamics.com <mailto:info at bitshift-dynamics.com>
Technischer
Support: support at bitshift-dynamics.com
<mailto:support at bitshift-dynamics.com>
Buchhaltung:
invoice at bitshift-dynamics.com <mailto:invoice at bitshift-dynamics.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20190206/774bc984/attachment.html>
More information about the Development
mailing list