PDA

View Full Version : linker error during signal declaration



riarioriu3
27th June 2012, 17:26
1.inside a.h
2.#include "b.h"
3.class A:public QObject
4.{
5.Q_OBJECT
6.public:
7.A();
8.public:
9.B *b;
10.slot:
11.A* retobj();
12.};
13.inside a.cpp
14.A::A()
15.{
16.b= new B();
17. QObject::connect(b,SIGNAL(returnObj(),this,SLOT(re tobj()));
18.
19.}
20.A * A::retobj()
21.{
22.return this ;
23.}
24.//----------------
25.inside b.h
26.
27.class A; //forward declaration
28.class B:public QObject
29.{
30.Q_OBJECT
31.public:
32.B();
33.A *a1;
34.public:
35.void hello();
36.signal:
37.A* returnObj();
38.};
39.//------------------
40.inside b.cpp
41.B::B()
42.{
43.
44.}
45.void B::hello()
46.{
47.a1= emit returnObj();
48.}
49.//------------------
50.inside main
51.
52.#include "a.h"
53.#include"b.h"
54.int main()
55.{
56.A * a2= new A();
57.B * b2=new B();
58.b->hello();
59.}
60.//-------------------------

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 ..

ChrisW67
28th June 2012, 00:02
My eyes are bleeding. For the sake of everyone's eyes please use
... tags around you code. The forum will preserve indenting, suppress the smileys, and even number the lines for you.

This code cannot compile as presented.

a.cpp will not compile as presented: there is no declaration of A.
There no inclusion of any Qt header to declare QObject.
Line 10 "slot" does not name a type
Line 17 mismatched parentheses
Line 36 "signal" does not name a type
There is no variable b in scope at line 58.
Redefinition of class B because there are no include guards
More that I'd be wasting time listing.


Even if it did compile:

Line 16 and 17. A creates a private B and connects that to its slot. You never use this 'b'.
Line 11. Slots can return values when called as a normal function, but not through a signal/slot connection.
Line 37. Signals do not return values
Line 47. Signals do not return values