PDA

View Full Version : Possibly an inheritance problem with QObject?



chadkeck
4th November 2008, 05:14
I've got classes set up like so (where an indent is inherits from):

Wizzy
BranchWizzy
InputWizzy
LoopWizzy
NamedWizzy
DatumWizzy
ProcedureWizzy
OutputWizzy
SinkWizzy
SourceWizzy

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:

OutputWizzy.cpp: In constructor `OutputWizzy::OutputWizzy(QObject*)':
OutputWizzy.cpp:9: error: `b' undeclared (first use this function)
OutputWizzy.cpp:9: error: (Each undeclared identifier is reported only once for each function it appears in.)
OutputWizzy.cpp:9: error: `BranchWizzy' is not a type

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:

#ifndef WIZZY_H
#define WIZZY_H

#include "Property.h"
#include <QtGui>

class WizzyConnectionPoint;

class Wizzy : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT

public:
Wizzy( QObject* = NULL );
~Wizzy();
/* snip */
};
#endif


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!

Ginsengelf
4th November 2008, 07:54
It would be helpful to see outputwizzy.cpp...

spirit
4th November 2008, 08:27
multiply inheritance of QObject is not allowed in Qt4.

Ginsengelf
4th November 2008, 09:45
But QGraphicsPixmapItem is not derived from QObject, so that shouldn't cause an error.

Ginsengelf

pastor
4th November 2008, 10:08
It would be nice to look at outputwizzy.h

spirit
4th November 2008, 14:06
But QGraphicsPixmapItem is not derived from QObject, so that shouldn't cause an error.

Ginsengelf

sure, I didn't notice that. :)

chadkeck
4th November 2008, 18:04
Here's the header for the OutputWizzy:

#ifndef OUTPUT_WIZZY_H
#define OUTPUT_WIZZY_H

#include "Wizzy.h"
#include <QtGui>
class WizzyConnectionPoint;

class OutputWizzy : public Wizzy
{
Q_OBJECT

public:
OutputWizzy( QObject* = NULL );
/* snip */
};
#endif

And here's the code for the implementation:

#include "OutputWizzy.h"

#include "WizzyConnectionPoint.h"
#include <QtGui>

#include "BranchWizzy.h"
OutputWizzy::OutputWizzy( QObject *p_parent ) : Wizzy( p_parent )
{
BranchWizzy *b = new BranchWizzy();
/* snip */
}

Here's the BranchWizzy header:

#ifndef BRANCH_WIZZY_H
#define BRANCH_WIZZY_H

#include "Wizzy.h"
#include <QtGui>

class BranchWizzy : public Wizzy
{
Q_OBJECT

public:
BranchWizzy( QObject* = NULL );

public slots:

signals:

protected:

private:
};

#endif

And BranchWizzy implementation:

#include "BranchWizzy.h"

#include "WizzyConnectionPoint.h"
#include <QtGui>

BranchWizzy::BranchWizzy( QObject *p_parent ) : Wizzy( p_parent )
{
/* snip */
}

Anyone see anything I'm overlooking? Thanks again!

pastor
4th November 2008, 18:21
Stange. I don't see anything

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

chadkeck
5th November 2008, 02:26
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:


enum WizzyType
{
ProcedureWizzy = 1,
BranchWizzy = 2,
LoopWizzy = 3,
DatumWizzy = 4,
InputWizzy = 5,
OutputWizzy = 6,
SourceWizzy = 7,
SinkWizzy = 8,
BaseWizzy = 0
};


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!