Problem with creating dynamic library



  • 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



  • 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.?



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



  • 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?



  • [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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.