Results 1 to 9 of 9

Thread: Issues with connecting signal slot in case of multiple inheritance

  1. #1
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Issues with connecting signal slot in case of multiple inheritance

    Hi,

    I am trying to map signal slot using QSignalMapper. The object I pass to the signalmapper is publicly derived from both QPushButton and CTest (CTest is not derived from any other class). CTest has only one int variable.
    so the declaration of my class will be

    class CClassy : public QPushButton,public CTest
    {
    }

    Now when I set the signal slot using signalmapper and pass the object of CClassy, it doesn't work. But if I pass an object of QPushButton, the same setup works fine.

    Is it because of Multiple inheritance?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    Don't forget the Q_OBJECT macro in your class!

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

    dpatel (13th July 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    I have Q_OBJECT macro in my class....

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Base
    4. {
    5. public:
    6. int i;
    7. };
    8.  
    9. class MyButton : public QPushButton, public Base
    10. {
    11. Q_OBJECT
    12. public:
    13. int i;
    14. };
    15.  
    16. int main(int argc, char* argv[])
    17. {
    18. QApplication app(argc, argv);
    19.  
    20. MyButton b;
    21. b.setText("Click to close!");
    22. QObject::connect(&b, SIGNAL(clicked()), &app, SLOT(quit()));
    23. b.show();
    24.  
    25. return app.exec();
    26. }
    27.  
    28. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    works fine for me. Your error must be somewhere else.

  6. The following user says thank you to Lykurg for this useful post:

    dpatel (13th July 2010)

  7. #5
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    Didn't you forgot the Q_OBJECT macro: (my guess is that you did, because there is no other reason for that)
    Qt Code:
    1. class CClassy : public QPushButton, public CTest
    2. {
    3. Q_OBJECT
    4. //... rest of the class definition
    5. }
    To copy to clipboard, switch view to plain text mode 

    EDIT: My answer was too late... sorry...
    Last edited by Zlatomir; 13th July 2010 at 13:25.

  8. The following user says thank you to Zlatomir for this useful post:

    dpatel (13th July 2010)

  9. #6
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    Ya, this code works for me as well. So I guess the issue is with my code. Thanks for you time.

  10. #7
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    Didn't the above example from Lykurg's work ?? Do you cast from one type to another in your code somewhere ???

  11. #8
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    Ahh, I got the root cause of the issue. I was overriding mousepressevent() on my button class, but after doing my stuff, was not calling QPushButton::mousePressEvent(e). After adding that code, everything works fine.

    Thanks everyone.

  12. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Issues with connecting signal slot in case of multiple inheritance

    Quote Originally Posted by dpatel View Post
    Ahh, I got the root cause of the issue. I was overriding mousepressevent() on my button class, but after doing my stuff, was not calling QPushButton::mousePressEvent(e).
    I "love" that kind of errors, they drive you crazy and you search everywhere but can't find anything. With this kind of errors I wast houres week after week!

Similar Threads

  1. Multiple Signal in a slot
    By QAlex in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2009, 11:39
  2. Replies: 2
    Last Post: 9th September 2009, 00:26
  3. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28
  4. Replies: 3
    Last Post: 11th January 2008, 17:34
  5. Multiple Inheritance & Qt
    By kefeng.chen in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2006, 18:37

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.