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. Problem with creating dynamic library
Forum Updated to NodeBB v4.3 + New Features

Problem with creating dynamic library

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.0k 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.
  • N Offline
    N Offline
    Nortrom
    wrote on 16 Oct 2012, 17:12 last edited by
    #1

    Hi everyone. I have to make plugin system for my application. But i'm new to c++ and qt, though have some basic knowledge.
    I'm trying to create a plugin and load it in my program by calling
    @
    QPluginLoader loader;
    loader.setFileName("PolygonController.dll");
    if (!loader.load())
    {
    qWarning( "This is not Qt plugin or plugin not match out Qt Libraries" );
    qDebug() << loader.errorString();
    };

    QObject * qobj = qobject_cast< QObject* >( loader.instance() );
    if (qobj) qWarning("its qobject");
    ShapeController * controller = qobject_cast<ShapeController* > (qobj);
    if ( !controller )
    {
      qWarning( "its not ShapeController" );
    };
    

    @

    and output is "its qobject. its not ShapeController"

    I guess the problem is that i don't use interface, i use a virtual class.
    @
    #ifndef SHAPEController_H
    #define SHAPEController_H
    #include <e:/qt_progects/paint/activatebutton.h>
    #include <e:/qt_progects/paint/paintscene.h>

    class ShapeController: public QObject
    {
    Q_OBJECT
    public:
    virtual void keyPressed (QKeyEvent *e) = 0;
    void setScene (PaintScene *scene);
    void loseScene ();
    bool scribbling;
    QString name;
    ActivateButton *activateButton;
    PaintScene *scene;
    public slots:
    virtual void mousePressed (QGraphicsSceneMouseEvent *e) = 0;
    virtual void mouseMoved (QGraphicsSceneMouseEvent *e) = 0;
    virtual void mouseReleased (QGraphicsSceneMouseEvent *e) = 0;
    private:
    };

    Q_DECLARE_INTERFACE( ShapeController,
    "com.nort.ShapeController.Interface.version/1.0")

    #endif // SHAPEController_H
    @

    Interfaces don't suit me well, because that metods - setScene and loseScene, +some fields are same for derived classes, and i need that slots in my pre-definition.

    My dll goal is to override that virtual methods
    @class PolygonController: public ShapeController
    {
    //Q_INTERFACES(ShapeController)
    public:
    PolygonController();
    void keyPressed(QKeyEvent *e);
    PolygonItem *current;
    public slots:
    void mousePressed (QGraphicsSceneMouseEvent *e);
    void mouseMoved (QGraphicsSceneMouseEvent *e);
    void mouseReleased (QGraphicsSceneMouseEvent *e);
    private:

    };@

    so i can load all my shape controllers (i have line, ellipse, rect, polygon controllers) in run-time from dll's.

    The question is what am i doing wrong, maybe there is another way to solve this?
    sorry for grammatical mistakes i have made, english is not my native language

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 17 Oct 2012, 06:28 last edited by
      #2

      What you show there is no interface, it's a class definition that also requires some implementation. Where is the class ShapeController implemented, especially the methods ShapeController::setScene etc.?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nortrom
        wrote on 17 Oct 2012, 10:26 last edited by
        #3

        in ShapeController.cpp . This code works already, i just have to export my derived classes into dll's.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on 17 Oct 2012, 14:07 last edited by
          #4

          So you export ShapeController from a dll that is used by the plugin and the main app? ok, so that is not the problem. Did you debug the whole thing and expand the macros for plugins / checked what loader.instance returned?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Nortrom
            wrote on 17 Oct 2012, 14:50 last edited by
            #5

            [quote author="Gerolf" date="1350482862"]So you export ShapeController from a dll that is used by the plugin and the main app?[/quote]
            ShapeController is already in my main project, and i use him with #include <waytofile/shapecontroller.h> in my dll.

            [quote author="Gerolf" date="1350482862"] ok, so that is not the problem. Did you debug the whole thing and expand the macros for plugins / checked what loader.instance returned?[/quote]

            as i wrote before,
            @
            QObject * qobj = qobject_cast< QObject* >( loader.instance() );

            if (qobj) qWarning("its qobject");
            
            ShapeController * controller = qobject_cast<ShapeController* > (qobj);
            
            if ( !controller )
            
            {
            
              qWarning( "its not ShapeController" );
            
            };@
            

            output is "its qobject"
            and "its not ShapeController"

            but what do u mean by "expand the macros for plugins"?
            i use that macros:
            @Q_DECLARE_INTERFACE( ShapeController,

            "com.nort.ShapeController.Interface.version/1.0")@

            @Q_INTERFACES(ShapeController)@

            @Q_EXPORT_PLUGIN2 ( polygoncontroller, PolygonController )@
            which need to create correct plugin, and plugin loads correctly from dll, but it inherits only qobject

            1 Reply Last reply
            0

            1/5

            16 Oct 2012, 17:12

            • Login

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