Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Conversion from QProperty to QBinding
Forum Updated to NodeBB v4.3 + New Features

Conversion from QProperty to QBinding

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 200 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I have adopted the following pattern when writing my QML-facing C++ property classes:

    class CProp : public QObject
    {
        Q_OBJECT
        QML_ELEMENT
        QML_UNCREATABLE("Controlled by C++")
    
        Q_PROPERTY(qreal x BINDABLE getBindableX READ default FINAL)
    private:
        QProperty<qreal> m_X;
    
    public:
         QBindable<qreal> getBindableX() { return &m_X;}
    };
    
    

    It's easy to write, it's convenient, and it seems to work.
    Two things trouble me:

    • The conversion from QProperty to QBindable via '&' does not seem to be documented. I must have taken it from some blog post or example, but I'm worried that I use an unsupported implicit conversion that might go away in the future
    • Could the getter be const? Does a QBindable allow changing the property within?
    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      So I suspect things work because QUntypedBindable (base class of QBindable) has a constructor accepting a template parameter pointer ("Property"), so my guess is that "&m_X" provides a pointer to QProperty<qreal>, which is accepted as template parameter in the constructor of QUntypedBindable. Then the whole thing is cast to QBindable, but is that safe?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved