
Originally Posted by
amleto
As a precursor I will just say that you have poor design and you shouldn't need to write code like that!!
To deal with your actual problem that has nothing to do with qt (and so this is the wrong forum for your question...) :
In your foreign class cpp file you need to #include "bmw.h" or whatever header contains your BMW class.
In your foreign class hpp file you need to forward declare the class
e.g.
class BMW;
class foreignclass
{
public:
void use_bmw(bmw* ptr);
};
class BMW;
class foreignclass
{
public:
void use_bmw(bmw* ptr);
};
To copy to clipboard, switch view to plain text mode
Thank you very much for your comment, It was helpful.
Excuse me for rejecting your judgement on my design, but I simply forgot to declare the class BMW in my foreign class, but that's still not the problem.
The class won't take BMW* as a parameter. Here are the points in the code where the problem is
InterfaceHndler.h >>Foreign class
#ifndef INTERFACEHNDLER_H
#define INTERFACEHNDLER_H
#include <bmw.h>
#include <KnightsComponent.h>
#include <scene.h>
#include <scenemainmenue.h>
#include <QGraphicsView>
class InterfaceHndler
{
class BMW;
public:
InterfaceHndler();
Scene *chessBoard;
SceneMainMenue *MW;
KnightsComponent *button_ng;
void buildMm(BMW*);
void buildGame();
};
#endif // INTERFACEHNDLER_H
#ifndef INTERFACEHNDLER_H
#define INTERFACEHNDLER_H
#include <bmw.h>
#include <KnightsComponent.h>
#include <scene.h>
#include <scenemainmenue.h>
#include <QGraphicsView>
class InterfaceHndler
{
class BMW;
public:
InterfaceHndler();
QGraphicsView *boardHndler;
Scene *chessBoard;
SceneMainMenue *MW;
QImage *Logo;
QGraphicsView *display;
QGraphicsScene *displayScene;
KnightsComponent *button_ng;
void buildMm(BMW*);
void buildGame();
};
#endif // INTERFACEHNDLER_H
To copy to clipboard, switch view to plain text mode
BMW.h file
#ifndef BMW_H
#define BMW_H
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <interfacehndler.h>
{
//Member variables
public:
InterfaceHndler Ih;
public: BMW();
};
#endif // BMW_H
#ifndef BMW_H
#define BMW_H
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <interfacehndler.h>
class BMW : public QMainWindow
{
//Member variables
public:
InterfaceHndler Ih;
public: BMW();
};
#endif // BMW_H
To copy to clipboard, switch view to plain text mode
I followed this methodology of design to allow my mouse event inside my (SceneMainMenue *MW) variable to respond to custom button clicking, and build other scenes in my main window class. I don't think that my design is poor, it's only a matter of making the BMW ptr works as a parameter....
I didn't modify the code, I just encapsulated the components into the interfaceHandler class. All I need is to know how to pass my BMW ptr as a parameter into the interface handler class, so I can manage button clicking..
the problem is not my design. The problem isn't Qt. The problem is simply that QGraphicsScene's mouse event is local.. I'm just trying to escape that locality by simple object communication.
It worked with simpler classes, but failed with QMainWindow subclasses (Any subclass from QMainWindow).
Added after 4 minutes:
I edited the following :
1-Functions are no longer reside in BMW ; they are defined in the interface handler.
2-The interfaceHndler class can manage the adding & deleting of elements from/ to the main window by receiving a pointer to to that window as a parameter in its native functions
Added after 5 minutes:
BTW, I don't want a simple solution like (adding a main QGraphicsScene) to the main window first, and implementing the mouse event in it, because all I want is simply allowing different objects in different classes to communicate by adding pointers the the destination class through a function.
I just want to know why I can't pass a QMainWindow as a pointer..
lol, sorry for talking too much, but I'm a student, and I need to learn..
Bookmarks