[Development] Enum classes in signals?
Dmitriy Purgin
dpurgin at gmail.com
Tue Feb 5 18:16:17 CET 2019
Hi Jason,
in one of the projects with Qt 5.9 I used enum classes in signals and slots
and it worked fine, even with the new Q_NAMESPACE thing. One thing though:
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.
Another thing is if you use QML and expose the namespaced enum classes to
QML: it works fine inside QML but if you call a Q_INVOKABLE of a C++ class
and try to pass an enum class from QML to it, you'll get garbage in that
C++ method. I ended up removing Q_INVOKABLE from the "normal" methods that
used enum classes, and added Q_INVOKABLE overloads with int parameters to
be called from QML. I have no idea if it would work without namespaces
though.
Cheers
Dmitriy
On Tue, Feb 5, 2019 at 6:06 PM Jason H <jhihn at gmx.com> wrote:
> > Sent: Tuesday, February 05, 2019 at 11:58 AM
> > From: "Thiago Macieira" <thiago.macieira at intel.com>
> > To: development at qt-project.org
> > Subject: Re: [Development] Enum classes in signals?
> >
> > On Tuesday, 5 February 2019 08:43:03 PST Jason H wrote:
> > > While I prefer enum classes myself, I just had to connect to a signal
> with
> > > one in it. This was unfortunate as I was attempting to use the old
> > > connection syntax SIGNAL()/SLOT() macros. I was not aware that the old
> > > syntax were being deprecated? What is the policy on this?
> >
> > They're not exactly deprecated, but they're older than the new syntax
> and they
> > don't check at compile time that the connection can succeed.
> >
> > > Should signals not use enum classes?
> >
> > Unknown. I don't see why they shouldn't, but you haven't shared any
> error
> > messages, so I can't tell.
> >
> > > Should Qt not use enum classes?
> >
> > Enum classes are fine in Qt.
> >
> > > Should Qt support old connection syntax? Where/when?
> >
> > Yes. It should be supported for the millions of lines of code that
> existed
> > before the new syntax was introduced in 2012.
> >
> > > Should all new connections be in the modern syntax?
> >
> > Yes, if you can.
>
> Great thanks for clarifying that. I use Qt principals in my own
> application code (they tend to be the best - well reasoned at least). So if
> there was something that I hadn't considered, I'd want to take that into
> account and avoid any gotchas down the road. I just started using enum
> classes myself.
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20190205/8a6050dc/attachment.html>
More information about the Development
mailing list