PDA

View Full Version : Access QML enumeration from C++



sedi
14th April 2016, 12:58
Hi,
I have a Text Item that uses different kinds of Alignment and must be able to take this information from a C++ model. For example, I want to be able to set:


delegate: Text {
verticalAlignment: model.alignment // Text.AlignVCenter, Text.AlignTop or Text.AlignBottom
...
}

I have not found anything about this in the docs (there is some stuff for "the other way 'round", for exposing c++ enums to QML of course)

Is there a "best practice" for handling this problem?

anda_skoa
14th April 2016, 13:12
Those enum value are from a C++ enum, Qt::AlignmentFlag
You could try letting the model return the respective Qt::AlignmentFlag value

Cheers,
_

sedi
14th April 2016, 21:49
Cool, you are absolutely right! How did you know (apart from: you just awesomely did :cool:)?
Where can I find such information in similar cases?

I didn't succeed in finding any relevant source of information about these connections.

anda_skoa
15th April 2016, 10:29
Everything in QML, aside from its keywords and primitive types, comes from C++.

So any enum value must have been exported from C++.

Since Qt has alignment flags in its C++ API, it was a logical conclusion that these would be the same values that got exported to QML.

Cheers,
_