How did you declare that slot? Could you also post the .pro file?
How did you declare that slot? Could you also post the .pro file?
Hi, the error message above is at runtime (in console).
I saw now the problem is in other place...
}Qt Code:
//myWidget.h class MyWidget { MainForm* w;To copy to clipboard, switch view to plain text mode
When I use in costructor of MyWidget: "connect(this, SIGNAL(myUpdate()), w, SLOT(myUpdateWidgets()) );" w pointer refers to MainForm;
But if I change in 'myMainForm* w' (in mywidget.h), compiler says me 'class redefinition error....' (error refers to line "class myMainForm {...." in mymainform.h)
I need a pointer to myMainForm class from MyWidget class (as It was for MainForm..)
Thanks
Regards
Could you at least learn to post exact error messages?Originally Posted by mickey
If you need that pointer only to make the connection, then make this connection in a different place (where you have both pointers).I need a pointer to myMainForm class from MyWidget class (as It was for MainForm..)
Thanks. The error is:
I need to obtain his pointer here.Qt Code:
mymainform.h(4): error C2011: 'myMainForm' : 'class' type redefinitionTo copy to clipboard, switch view to plain text mode
I don't undertand why for MainForm there aren't problems (I declareed pointer to myMainForm in the same way of pointer to MainForm:
Qt Code:
//mywidget.h class MyWidget { MainForm* w; myMainForm* myw; }To copy to clipboard, switch view to plain text mode
Regards
What do you have in 4th line of the mymainform.h class?Originally Posted by mickey
Did you guard all your headers using following code?Qt Code:
#ifndef __FILE_NAME_H__ #define __FILE_NAME_H__ ... #endif // __FILE_NAME_H__To copy to clipboard, switch view to plain text mode
Now compile successful.
the line 4 is:
in mywidget.h I have #include "mymainform.h"Qt Code:
class myMainForm : public MainFormTo copy to clipboard, switch view to plain text mode
in mymainform.h I have #include "mywidget.h"
Is it a cycle!? Is this the cause?
Thanks
Regards
Yes, it is. You can avoid it using forward declaration.Originally Posted by mickey
mickey (8th March 2006)
sorry,
what does 'forward declarations' mean?
Regards
Ever tried google?Originally Posted by mickey
![]()
Hi I tried this and work!
A Question: to toggle include "mywidget.h" I needed to insert #include "mywidget.h" inside mymainform.cpp. Wasn't it the same? Why is better of my previus code (apart avoid cycle problem).Qt Code:
#ifndef MYMAINFORM_H #define MYMAINFORM_H //#include "mywidget.h" class MyWidget; class myMainForm : public MainForm { Q_OBJECT public: ~myMainForm(); MyWidget* myWidget2; MyWidget* myWidget3; public slots: signals: void myMainFormUpdate(); }; #endifTo copy to clipboard, switch view to plain text mode
Thanks
Regards
You should use forward declarations whenever possible. Use includes only when forward declaration is not suitable.Originally Posted by mickey
Forward declaration is adequate for pointers and references. You have to use includes when compiler needs to know the size of a type. This is the case when you inherit from a class or you have an aggregate object as a class member variable.
By filling your header files with unnecessary includes only generates extra dependencies and slows compiling down for no purpose at all.
Bookmarks