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. Accessing Qml from C++ plugin.
Forum Updated to NodeBB v4.3 + New Features

Accessing Qml from C++ plugin.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 917 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.
  • D Offline
    D Offline
    Darkmalex
    wrote on last edited by
    #1

    Basicly what I want is a pointer to QQmlApplicationEngine engine that can be accessed from a c++ plugin that I wrote. So any ideas?
    P.S. I have tried almost everything I could, so I would need a full step-by-step explanation on what shold I do, otherwise I might make the same mistakes I'm currently dealing with.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Try this.

      class ShapeInterface
      {
      public:
      ShapeInterface(){}
      virtual void myname() = 0;
      virtual void drawme() = 0;
      virtual void setEng(QQmlEngine *eng)=0;
      };

      Implement this plugin using the Plugin mechanism.

      QQmlEngine *eng = viewer.engine();
      
      QPluginLoader bosch("PthinksPlugin.dll");
      QObject *obj = bosch.instance();
      
      if (obj ) {
          qDebug() << "instance creation succes" <<endl;
          ShapeInterface *iface =
          qobject_cast<ShapeInterface*>(obj);
          iface->myname();
          eng->setObjectName("Plugin");
          iface->setEng(eng);
      

      }

      If you need complete sample I can dump it.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Darkmalex
        wrote on last edited by
        #3

        [quote author="Dheerendra" date="1406824938"]Try this.

        class ShapeInterface
        {
        public:
        ShapeInterface(){}
        virtual void myname() = 0;
        virtual void drawme() = 0;
        virtual void setEng(QQmlEngine *eng)=0;
        };

        Implement this plugin using the Plugin mechanism.

        QQmlEngine *eng = viewer.engine();
        
        QPluginLoader bosch("PthinksPlugin.dll");
        QObject *obj = bosch.instance();
        
        if (obj ) {
            qDebug() << "instance creation succes" <<endl;
            ShapeInterface *iface =
            qobject_cast<ShapeInterface*>(obj);
            iface->myname();
            eng->setObjectName("Plugin");
            iface->setEng(eng);
        

        }

        If you need complete sample I can dump it.[/quote]

        Wow, newer thought it would get this complicated. :)
        Actualy this is an sub-question of one: "I've already asked":http://qt-project.org/forums/viewthread/45545/ . Here you can find the code.
        The only progress I've made is that stack overflow guys figured out this line: @QCoreApplication::postEvent(engine->rootObjects().first, event);@
        Everything looks ok, but the problem is in accessing engine. I've tried everything I know about pointers in Qt. As For your suggestion, Dheerendra, I would gladly check it if you would show me how it works in example of my plugin, which I gave link to above. Thanks in advance.

        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