Linker error for signal declaration .
-
i have 2 classes
@
inside a.h
#include "b.h"
class A:public QObject
{
Q_OBJECT
public:
A();
public:
B b;
slot:
A retobj();
};
@inside a.cpp:
@
A::A()
{
b= new B();
QObject::connect(b,SIGNAL(returnObj(),this,SLOT(retobj()));
}A * A::retobj()
{
return this ;
}
//----------------
@
inside b.h:
@
class A; //forward declaration
class B:public QObject{
Q_OBJECT
public:
B();
A a1;
public:
void hello();
signal:
A returnObj();
};
//------------------
@
inside b.cpp:
@
B::B()
{}
void B::hello()
{
a1= emit returnObj();
}
//------------------
@
inside main:
@
#include "a.h"
#include"b.h"
int main()
{
A * a2= new A();
B * b2=new B();
b->hello();
}
//-------------------------@The above code is compiling but during linking its showing some problem ..something like unresolved external symbol returnObj();
What might be the reason ..
Thankx in adv ..[Edit: Cleaned up code formatting, added indentation for legibility -- mlong]
-
Did you re-run qmake?
Be aware that a signal returning a value does work in certain circumstances only (direct or blocking connection, last value from multiple connections).
-
Hi BibekKumar,
SIGNAL should not be used in this way, and it shouldn't have a return value.
Regards,
-
the correct use for the signal would be like this:
@
signals:
void returnObj(A*);
@corresponding to slot:
@
public slots: //...or private slots:
void gotObject(A* a1);
@[EDIT] - error corrected... (thanks for pointing that out Mr.Universe :) )
-
Another mistake are your keywords: its not "signal" and "slot" but "signals" and "slots"...
Is this really the original source-code? because this shouldn't compile at all, when I try to define a signal with "signal:", I get the following compiler-error: "Not a signal or slot declaration"