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. [SOLVED] Proper way of creating complex QDeclarativeItem class exposed to qml by QDeclarativeExtensionPlugin
QtWS25 Last Chance

[SOLVED] Proper way of creating complex QDeclarativeItem class exposed to qml by QDeclarativeExtensionPlugin

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.7k Views
  • 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.
  • T Offline
    T Offline
    tolszak
    wrote on last edited by
    #1

    Hello all,
    I need some expertise.

    Let's assume that I have class A that inherits from QDeclarativeItem. I want this item to be composed from few QDeclarativeComponent's created in A constructor. I need pointer tor QDeclarativeEngine for this.

    I've achieved this by:

    @
    QmlPlugin: public QDeclarativeExtensionPlugin {
    ...
    public:
    static QDeclarativeEngine * engine;
    ....
    void initializeEngine ( QDeclarativeEngine * _engine, const char * uri ) {
    engine = _engine;
    QDeclarativeExtensionPlugin::initializeEngine(engine,uri);
    }
    ....
    };
    @

    Now I can get QDeclarativeEngine * from inside contructor of A class (QmlPlugin::engine), but...

    • If I have 2 QDeclarativeView's that load 2 qml files that import this plugin, will it create 2 QDeclarativeEngine's and only one will be stored in this static variable?
    • Is there more proper way of doing this?
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      From within the class A constructor, you should be able to call qmlEngine(this) to get the engine that constructed the item. (I'm not sure if this function is documented -- you could also use QDeclarativeEngine::contextForObject(this)->engine())

      Regards,
      Michael

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tolszak
        wrote on last edited by
        #3

        Hello,
        I supposed that there is more convenient way for getting pointer to QDeclarativeEngine from inside the plugin. As far as I know qmlEngine function is not documented but QDeclarativeEngine::contextForObject I have skipped somehow.
        Thank You for hints!

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tolszak
          wrote on last edited by
          #4

          qmlEngine and QDeclarativeEngine::contextForObject returns NULL in class A constructor.
          I've done creating additional internal components in A::onCompleted - there i can get pointer to engine from qmlEngine function.

          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