Results 1 to 9 of 9

Thread: Possibly an inheritance problem with QObject?

  1. #1
    Join Date
    Jul 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Possibly an inheritance problem with QObject?

    I've got classes set up like so (where an indent is inherits from):
    Qt Code:
    1. Wizzy
    2. BranchWizzy
    3. InputWizzy
    4. LoopWizzy
    5. NamedWizzy
    6. DatumWizzy
    7. ProcedureWizzy
    8. OutputWizzy
    9. SinkWizzy
    10. SourceWizzy
    To copy to clipboard, switch view to plain text mode 

    The problem is that when I try to include and use any class at the same level (e.g. Have an OutputWizzy create a BranchWizzy) it won't compile and gives the following message when trying to instantiate a BranchWizzy:
    Qt Code:
    1. OutputWizzy.cpp: In constructor `OutputWizzy::OutputWizzy(QObject*)':
    2. OutputWizzy.cpp:9: error: `b' undeclared (first use this function)
    3. OutputWizzy.cpp:9: error: (Each undeclared identifier is reported only once for each function it appears in.)
    4. OutputWizzy.cpp:9: error: `BranchWizzy' is not a type
    To copy to clipboard, switch view to plain text mode 

    I'm using Qt 4.4.3 and mingw on Windows XP.
    Everything compiles fine if I don't have a Wizzy subclass try to use any other Wizzy subclass.

    Here's a snip of the Wizzy.h:
    Qt Code:
    1. #ifndef WIZZY_H
    2. #define WIZZY_H
    3.  
    4. #include "Property.h"
    5. #include <QtGui>
    6.  
    7. class WizzyConnectionPoint;
    8.  
    9. class Wizzy : public QObject, public QGraphicsPixmapItem
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. Wizzy( QObject* = NULL );
    15. ~Wizzy();
    16. /* snip */
    17. };
    18. #endif
    To copy to clipboard, switch view to plain text mode 

    The Wizzy subclasses inherit the Wizzy class in a similar manner. I am simply out of ideas of why one subclass "can't see" another.

    Any ideas? I can post any other code anyone would like to see. Thanks!

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Possibly an inheritance problem with QObject?

    It would be helpful to see outputwizzy.cpp...

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Possibly an inheritance problem with QObject?

    multiply inheritance of QObject is not allowed in Qt4.

  4. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Possibly an inheritance problem with QObject?

    But QGraphicsPixmapItem is not derived from QObject, so that shouldn't cause an error.

    Ginsengelf

  5. #5
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: Possibly an inheritance problem with QObject?

    It would be nice to look at outputwizzy.h

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Possibly an inheritance problem with QObject?

    Quote Originally Posted by Ginsengelf View Post
    But QGraphicsPixmapItem is not derived from QObject, so that shouldn't cause an error.

    Ginsengelf
    sure, I didn't notice that.

  7. #7
    Join Date
    Jul 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Possibly an inheritance problem with QObject?

    Here's the header for the OutputWizzy:
    Qt Code:
    1. #ifndef OUTPUT_WIZZY_H
    2. #define OUTPUT_WIZZY_H
    3.  
    4. #include "Wizzy.h"
    5. #include <QtGui>
    6. class WizzyConnectionPoint;
    7.  
    8. class OutputWizzy : public Wizzy
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. OutputWizzy( QObject* = NULL );
    14. /* snip */
    15. };
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    And here's the code for the implementation:
    Qt Code:
    1. #include "OutputWizzy.h"
    2.  
    3. #include "WizzyConnectionPoint.h"
    4. #include <QtGui>
    5.  
    6. #include "BranchWizzy.h"
    7. OutputWizzy::OutputWizzy( QObject *p_parent ) : Wizzy( p_parent )
    8. {
    9. BranchWizzy *b = new BranchWizzy();
    10. /* snip */
    11. }
    To copy to clipboard, switch view to plain text mode 

    Here's the BranchWizzy header:
    Qt Code:
    1. #ifndef BRANCH_WIZZY_H
    2. #define BRANCH_WIZZY_H
    3.  
    4. #include "Wizzy.h"
    5. #include <QtGui>
    6.  
    7. class BranchWizzy : public Wizzy
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BranchWizzy( QObject* = NULL );
    13.  
    14. public slots:
    15.  
    16. signals:
    17.  
    18. protected:
    19.  
    20. private:
    21. };
    22.  
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    And BranchWizzy implementation:
    Qt Code:
    1. #include "BranchWizzy.h"
    2.  
    3. #include "WizzyConnectionPoint.h"
    4. #include <QtGui>
    5.  
    6. BranchWizzy::BranchWizzy( QObject *p_parent ) : Wizzy( p_parent )
    7. {
    8. /* snip */
    9. }
    To copy to clipboard, switch view to plain text mode 

    Anyone see anything I'm overlooking? Thanks again!

  8. #8
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: Possibly an inheritance problem with QObject?

    Stange. I don't see anything

    Can you post a minimal sources for reproducible? (I want to reproduce this on my local machine)

  9. #9
    Join Date
    Jul 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Possibly an inheritance problem with QObject?

    Thanks to pastor's comment I went ahead and started stripping out code. It came down to an Enum I had that had in the Wizzy.h had exact names of the other Wizzy classes. For example:

    Qt Code:
    1. enum WizzyType
    2. {
    3. ProcedureWizzy = 1,
    4. BranchWizzy = 2,
    5. LoopWizzy = 3,
    6. DatumWizzy = 4,
    7. InputWizzy = 5,
    8. OutputWizzy = 6,
    9. SourceWizzy = 7,
    10. SinkWizzy = 8,
    11. BaseWizzy = 0
    12. };
    To copy to clipboard, switch view to plain text mode 

    Rookie mistake, I can't believe I haven't run into it before. Too bad the compiler error message wasn't any help

    Thanks for everyone's time!

Similar Threads

  1. Problem with Destructor of QObject
    By mikro in forum Qt Programming
    Replies: 5
    Last Post: 9th July 2006, 19:05
  2. subclassing/inheritance QObject problem
    By cbeall1 in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 17:49

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.