[Development] [QML] Assigning ints to enumeration properties

Laszlo Papp lpapp at kde.org
Wed Mar 6 12:11:09 CET 2013


On Wed, Mar 6, 2013 at 9:48 AM, Olivier Goffart <olivier at woboq.com> wrote:

>  This is not a warning, this is an error in C++
>
> enum Foo { A ,  B };
> Foo bar = 1; // error: invalid conversion from ‘int’ to ‘Foo’
> int blah = bar; // No warning. unless you use enum class then it is a
> error.
>

At least, I can second that even with msvc variants, but perhaps Alan meant
-fpermissive or so.

I think implicit casts is *not* a good idea.
>
> Allowing explicit casts should be good.
>

That would be a bit uglier in QML than a static or function type explicit
cast like in C++ unless there is a nice trick not to make map, object,
mapper function or so for enums with many values. Perhaps parseInt() or
something similar? I would not know.

If there is no nice trick, I would suggest allowing it (perhaps with a
warning on the console?) because I do not wish to maintain such code if I
know what I am doing. :)

Laszlo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130306/a5303500/attachment.html>


More information about the Development mailing list