Results 1 to 4 of 4

Thread: Slot inheritance

  1. #1
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Slot inheritance

    May be it was answered already, but I can't find a proper solution.

    1. I've base class. It does most of the work
    2. I've child classes that do more specific tasks

    Qt Code:
    1. class abstract_therapy : public QObject
    2. {
    3. Q_OBJECT
    4. ...
    5. public:
    6. void testFunction();
    7. public slots:
    8. void testSlot();
    9. private:
    10. QTimer* m1;
    11. }
    To copy to clipboard, switch view to plain text mode 

    Child class :
    Qt Code:
    1. class B : public abstract_therapy
    2. {
    3. Q_OBJECT
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 

    And implementation
    Qt Code:
    1. void abstract_therapy::testFunction()
    2. {
    3. m1 = new QTimer(this);
    4. m1->connect(m1, SIGNAL(timeout()), this, SLOT(testSlot()));
    5. m1->setInterval(500);
    6. m1->start();
    7. }
    To copy to clipboard, switch view to plain text mode 

    In the program I've several classes inherited from abstract_therapy, B & C for example, and I don't use base class directly.

    Qt Code:
    1. abstract_therapy* _therapy;
    2. _therapy = new B;
    3. ...
    4. _therapy->testFunction();
    To copy to clipboard, switch view to plain text mode 
    And on connect I receive this message :
    No such slot B::testSlot()
    What's the right way to connect ?
    Last edited by kartun; 28th February 2011 at 12:39.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Slot inheritance

    just copy pasted your example and it works for me.

    tst.h
    Qt Code:
    1. class abstract_therapy : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. void testFunction();
    6. public slots:
    7. void testSlot(){ qDebug() << "in slot"; }
    8. private:
    9. QTimer* m1;
    10. };
    11.  
    12. class B : public abstract_therapy
    13. {
    14. Q_OBJECT
    15. public:
    16. void abc(){}
    17. };
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtCore>
    2.  
    3. #include "tst.h"
    4.  
    5. void abstract_therapy::testFunction()
    6. {
    7. m1 = new QTimer(this);
    8. m1->connect(m1, SIGNAL(timeout()), this, SLOT(testSlot()));
    9. m1->setInterval(500);
    10. m1->start();
    11. }
    12.  
    13. int main(int argc, char *argv[])
    14. {
    15. QCoreApplication a(argc, argv);
    16.  
    17. abstract_therapy* _therapy;
    18. _therapy = new B;
    19.  
    20. _therapy->testFunction();
    21.  
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 



    and here is the output


    Starting /home/nish/Desktop/progs/tst/tst-build-desktop/tst...
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot
    in slot

  3. The following user says thank you to nish for this useful post:

    kartun (28th February 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slot inheritance

    Ok, thanks for checking. Seems I cutted off something important that blocks my own execution queue ...
    Thanks to non really informative description of Qt, I just messed up with wrong slot signatures.
    Last edited by kartun; 28th February 2011 at 13:22.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Slot inheritance

    Quote Originally Posted by kartun View Post
    Thanks to non really informative description of Qt, I just messed up with wrong slot signatures.
    What's exactly non-informative?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. signal/slot problems with inheritance
    By Slewman in forum Qt Programming
    Replies: 11
    Last Post: 7th December 2010, 16:19
  2. Replies: 8
    Last Post: 13th July 2010, 15:08
  3. inheritance
    By mickey in forum General Programming
    Replies: 11
    Last Post: 28th September 2007, 22:54
  4. How much inheritance do you use?
    By Michiel in forum General Programming
    Replies: 8
    Last Post: 1st August 2006, 23:29
  5. QSA and inheritance
    By jwintz in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2006, 15:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.