Results 1 to 4 of 4

Thread: Access QML enumeration from C++

  1. #1
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Question Access QML enumeration from C++

    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:
    Qt Code:
    1. delegate: Text {
    2. verticalAlignment: model.alignment // Text.AlignVCenter, Text.AlignTop or Text.AlignBottom
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Access QML enumeration from C++

    Those enum value are from a C++ enum, Qt::AlignmentFlag
    You could try letting the model return the respective Qt::AlignmentFlag value

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    sedi (14th April 2016)

  4. #3
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Access QML enumeration from C++

    Cool, you are absolutely right! How did you know (apart from: you just awesomely did )?
    Where can I find such information in similar cases?

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

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Access QML enumeration from C++

    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,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    sedi (20th April 2016)

Similar Threads

  1. Access USB from Qt???
    By webquinty in forum Qt Programming
    Replies: 5
    Last Post: 6th June 2011, 09:40
  2. Can't access dll
    By waynew in forum Newbie
    Replies: 4
    Last Post: 15th November 2010, 14:06
  3. web access
    By ashwinibm in forum Newbie
    Replies: 1
    Last Post: 15th January 2010, 11:27
  4. Replies: 1
    Last Post: 13th September 2006, 13:14
  5. Replies: 7
    Last Post: 3rd February 2006, 11:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.