Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Template Class and QML
Forum Updated to NodeBB v4.3 + New Features

Template Class and QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 359 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.
  • S Offline
    S Offline
    St.Stanislav
    wrote on last edited by St.Stanislav
    #1

    Hello all!
    I did some steps in my investigations, but have faces with several problems (some of them I solved, some moved me to another way). But I have decided to wonder, about possibility of my idea. Can I create template class that can be used in QML?

    What I have tried:

    1. I inherited from QPair<T, P> and create my own
    structure Range<T>: public QPair<T, T> {}
    

    I have defined constructors, inner logic and so on. I have also registered my type with qRegisterMetaType for some specific template class, e.g. Range<quint32>. Everything looked like OK, but in QML all methods of Range were inaccessible (returned undefined value, e.g.). So I have tried to register it additionally with qmlRegisterType and found that staticMetaObject is not Range<quint32> member. As far I understand that's because of my Range type is not QObject (correct my if I wrong).

    1. Obviously, my second attempt was creating my Range as QObject derived class, but I faced big problem much more earlier: QObject does not support template.

    So my question is: can I create my own template class that can be used in QML? For my example above I wanted to use my own methods

    T lower() const {return QPair<T, T>::first;}
    T upper() const {return QPart<T, T>::second;}
    
    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