[SOLVED] Inheriting virtual slots and use the new QT5 connect flavour



  • Hi!

    If i create a class from a base class with virtual slots, the slots never get called with the new connect-flavour.
    If i use the old connect-syntax, the slot gets called. What could be the problem?

    @
    class BaseClass: public QObject
    {
    public slots:

    virtual void Slot1() = 0;
    virtual void Slot2() = 0;
    

    };

    class DerivedClass: public BaseClass
    {

    public slots:

    void Slot1();
    void Slot2();
    

    };
    @

    Why doesn't it work with the new connect-syntax but does with the old syntax?

    Thank you very much!



  • I have tried just now as well.Hope you are taking about the following new syntax It works fine.
    QObject::connect(&button,&QPushButton::clicked,&dobj,&DerivedClass::vslot2);

    I tried on Windows.



  • Hm...did you declare it as a pure virtual in the baseclass? Doesn't work here. Maybe the problem is that i connect to a slot of a class in dll-library.



  • It is same class as yours. I have added one more slot in base class. Dll also should not cause any issue.

    @class BaseClass : public QObject
    {
    Q_OBJECT
    public:
    explicit BaseClass(QObject *parent = 0);

    signals:

    public slots:
    void vslot0();
    virtual void vslot1() =0;
    virtual void vslot2() =0;
    };

    class DerivedClass : public BaseClass
    {
    Q_OBJECT
    public:
    explicit DerivedClass();

    signals:

    public slots:
    void vslot1();
    void vslot2();
    };@



  • I have my base in dll1 and my derivec in dll2. If i send the signal that connects with the slot of base-class, the slot in derived is never called.

    Did you try it with dlls?



  • I have not tried with dlls. Did you create plugin or is it plain dll ? Hope you have exported the functions in dll with extern "C" to avoid any name mangling issues.



  • Hi! I'm exporting the class. Is it required to export the DerivedClass? Or is it required to export the class and every method/function?

    Thank you for your help.



  • Works. Did a complete rebuild. Take care of Q_DECL_EXPORT ;-)


Log in to reply
 

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