PDA

View Full Version : connect



mickey
8th March 2006, 14:41
I I have code this below but I have and error on 1th connect


mywidget.cpp(113): error C2664: 'bool QObject::connect(const QObject *,const char *,const QObject *,const char *)' : cannot convert parameter 3 from 'myMainForm *' to 'const QObject *'


//constructor of MyWidget class
w = (MainForm*)this->topLevelWidget();
myw= (myMainForm*)this->topLevelWidget();
connect(this, SIGNAL(myUpdate()), myw, SLOT(myUpdateWidgets()) );
connect(this, SIGNAL(myUpdate()), w, SLOT(updateWidgets()) );



class MyWidget {
MainForm* w;
myMainForm* myw;
}
The 2nd connect works properly; Why this error on 1th? Isn't it the same? Thanks

jacek
8th March 2006, 15:07
The 2nd connect works properly; Why this error on 1th? Isn't it the same?
No, they're not the same. In second snippet a forward declaration is enough, because compiler needs only information about the size. In the first one the whole class definition must be visible (i.e. you must add proper #include statement), because compiler needs to know whether it can cast myMainForm to QObject.

Anyway, you don't need those casts (since both objects will be converted to QObject, before the connect() method is invoked). You can write it this way:
w = this->topLevelWidget();
connect(this, SIGNAL(myUpdate()), w, SLOT(myUpdateWidgets()) );
connect(this, SIGNAL(myUpdate()), w, SLOT(updateWidgets()) );

mickey
8th March 2006, 19:08
Hi, cast (MainForm*) is necessary; otherwise occur this error:

mywidget.cpp(70): error C2440: '=' : cannot convert from 'QWidget *' to 'MainForm *'
I didn't include "myMainForm"! Sorry please;
Thanks