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. QObject , more specifically is possible to get copy of a QObject-> and how?
Qt 6.11 is out! See what's new in the release blog

QObject , more specifically is possible to get copy of a QObject-> and how?

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 4 Posters 8.7k Views 3 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.
  • mrjjM mrjj

    Hi
    I assume you have something like
    QString myplug = qApp->applicationDirPath() + "/plugins/myplugin.dll";
    QPluginLoader loader (myplug);
    QObject* plugin = loader.instance();
    MyPluginInterface* myplugin_interface = qobject_cast<MyPluginInterface*>(plugin);
    // call function
    myplugin_interface->SomethingXXX();

    If u need more object from inside DLL, make a interface function that gives you what you need.

    If we still completely miss the point ;), could you please provide some code and more info about this plugin ?

    D Offline
    D Offline
    ddze
    wrote on last edited by ddze
    #12

    @mrjj

    I know that part as you showed I have already one instance of the plugin. The problem is that instance is sort of a template to drag and drop on a QGraphicsScene surface. The QMimeData has its own limits and I could not convert with best of my effort (including implementing<< >> operators to extract features on the scene , did not work.

    So the idea was to use the ordinary QMimeData as the media info about the data type in the QDropEvent than select an already initiataed MyInterface object as a template to copy it to different part of the free space. Since the copy of the QObject does not work ... very few options are left. I have already done << >> operators overloading but even that not completely since I can't use the << operator to stream a QGraphicsItem member.

    Perhaps to give up on QPluginLoader and load dll's differently, and into different containers not to QObject ...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #13

      Why not stream the data you need to create a new QGraphicsItem based on the "old one" ?

      By the way, QGraphicsItem is not a QObject.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 2 Replies Last reply
      0
      • SGaistS SGaist

        Why not stream the data you need to create a new QGraphicsItem based on the "old one" ?

        By the way, QGraphicsItem is not a QObject.

        D Offline
        D Offline
        ddze
        wrote on last edited by
        #14

        @SGaist

        I could do that , but the QGraphicsItem part has no any info about the internals of MyInterfaceClass , for example , I would not be able to call a particle function from my class ... only the parts inherited from QGraphicsItem. So basically I need the access to the interface

        kshegunovK 1 Reply Last reply
        0
        • D ddze

          @SGaist

          I could do that , but the QGraphicsItem part has no any info about the internals of MyInterfaceClass , for example , I would not be able to call a particle function from my class ... only the parts inherited from QGraphicsItem. So basically I need the access to the interface

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #15

          @ddze
          I'm not quite sure I understand what exactly you're trying to achieve, but you could create your graphics items in the plugin (on demand from the main application) and then pass them to the scene, or even return them as objects. Then your factory (incidentally being the plugin) has access to whatever internal data it needs to populate the graphics items.

          Read and abide by the Qt Code of Conduct

          D 1 Reply Last reply
          0
          • SGaistS SGaist

            Why not stream the data you need to create a new QGraphicsItem based on the "old one" ?

            By the way, QGraphicsItem is not a QObject.

            D Offline
            D Offline
            ddze
            wrote on last edited by
            #16

            @SGaist ,

            the article about why the copy of the QObject is disabled has mentioned the cloning. But there is no any clone functionality available either. Is it possible to do the cloning of the QObject somehow?

            1 Reply Last reply
            0
            • kshegunovK kshegunov

              @ddze
              I'm not quite sure I understand what exactly you're trying to achieve, but you could create your graphics items in the plugin (on demand from the main application) and then pass them to the scene, or even return them as objects. Then your factory (incidentally being the plugin) has access to whatever internal data it needs to populate the graphics items.

              D Offline
              D Offline
              ddze
              wrote on last edited by ddze
              #17

              @kshegunov

              yes but you are talking only on one instance, I would ....but I need either to copy and later modify its content (which is near impossible as i see) or a cloning of MyClassInterface object to multiple ones 1 ...* from single plugin dll QObject. The graphical part is just graphical ....(by the way the class inherits the QGraphicsItem object and implements the Paint ... so it draws itself no problem.

              kshegunovK 1 Reply Last reply
              0
              • D ddze

                @kshegunov

                yes but you are talking only on one instance, I would ....but I need either to copy and later modify its content (which is near impossible as i see) or a cloning of MyClassInterface object to multiple ones 1 ...* from single plugin dll QObject. The graphical part is just graphical ....(by the way the class inherits the QGraphicsItem object and implements the Paint ... so it draws itself no problem.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #18

                @ddze
                If you need many instances of your MyClassInterface then you shouldn't implement that interface in the plugin class. Instead add another interface to the plugin class that allows for you to create as many MyClassInterface instances as you wish.

                Read and abide by the Qt Code of Conduct

                D 1 Reply Last reply
                1
                • kshegunovK kshegunov

                  @ddze
                  If you need many instances of your MyClassInterface then you shouldn't implement that interface in the plugin class. Instead add another interface to the plugin class that allows for you to create as many MyClassInterface instances as you wish.

                  D Offline
                  D Offline
                  ddze
                  wrote on last edited by
                  #19

                  @kshegunov

                  reasonable suggestion, most likely the way to do this.

                  Thanks @kshegunov

                  kshegunovK 1 Reply Last reply
                  0
                  • D ddze

                    @kshegunov

                    reasonable suggestion, most likely the way to do this.

                    Thanks @kshegunov

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by kshegunov
                    #20

                    @ddze
                    No problem. As I mentioned the plugin acts (mostly) as a factory for objects, not as a data class, or GUI element. You simply request some feature (some object representing the feature) from the plugin, it creates it and returns an instance. Usually you don't expect the plugin object itself to provide the actual implementation of the feature, but to provide you with the means to obtain it. I hope I'm making sense.

                    Kind regards.

                    Read and abide by the Qt Code of Conduct

                    D 1 Reply Last reply
                    0
                    • kshegunovK kshegunov

                      @ddze
                      No problem. As I mentioned the plugin acts (mostly) as a factory for objects, not as a data class, or GUI element. You simply request some feature (some object representing the feature) from the plugin, it creates it and returns an instance. Usually you don't expect the plugin object itself to provide the actual implementation of the feature, but to provide you with the means to obtain it. I hope I'm making sense.

                      Kind regards.

                      D Offline
                      D Offline
                      ddze
                      wrote on last edited by
                      #21

                      @kshegunov

                      I see, acts as 1 ..1 association.

                      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