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. [SOLVED] Inheriting virtual slots and use the new QT5 connect flavour
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 10.5k 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.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    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!

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

      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.

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

      1 Reply Last reply
      0
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

        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.

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

          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();
          };@

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

          1 Reply Last reply
          0
          • jensen82J Offline
            jensen82J Offline
            jensen82
            wrote on last edited by
            #5

            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?

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

              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.

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

              1 Reply Last reply
              0
              • jensen82J Offline
                jensen82J Offline
                jensen82
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • jensen82J Offline
                  jensen82J Offline
                  jensen82
                  wrote on last edited by
                  #8

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

                  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