[PySide] Cannot pass enum by value

Hugo Parente Lima hugo.lima at openbossa.org
Wed May 30 20:09:18 CEST 2012


On Wednesday, May 30, 2012 11:33:54 AM John Cummings wrote:
> I uncovered a bug with the latest Shiboken when passing an enum by
> reference. Like Nathan, I have a bug report ready to go when the system
> comes back up.
> 
> In previous versions, you could pass an enum by reference to a method like
> so:
> 
> class Val
> {
> enum ValEnum { One, Other };
> ValEnum oneOrTheOtherEnumValue(ValEnum& enumValue) { return enumValue == One
> ? Other : One; }
> }
> 
> You get compilation errors with version 1.1.1 and with HEAD. The generated
> code is trying to use a pointer instead of reference. Previous version of
> Shiboken worked just fine (specifically, 1.0.7 worked, I'm not sure about
> other versions until 1.1.1).
> 
> Unlike Nathan, I don't have a patch ready. The workaround is obviously to
> pass an enum by value not by reference (which is admittedly a bit overkill
> anyway). If someone knows of a better solution, I'm willing to try it.

It can be passed by value unless it's a const reference, otherwise the 
following code wont work.

enum ValEnum { One, Other };
void oneOrTheOtherEnumValue(ValEnum& enumValue) {
    enumValue = Other;
}

ValEnum a = One;
oneOrTheOtherEnumValue(a);
// a should be equal to Other.

This is why Shiboken tries to use a pointer, but the code seems wrong anyway 
:-/.


 
> John Cummings
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120530/82e31546/attachment.sig>


More information about the PySide mailing list