Results 1 to 2 of 2

Thread: linker error during signal declaration

  1. #1
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default linker error during signal declaration

    1.inside a.h
    2.#include "b.h"
    3.class Aublic 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 Bublic 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 ..

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: linker error during signal declaration

    My eyes are bleeding. For the sake of everyone's eyes please use [code]...[/code] 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
    Last edited by ChrisW67; 28th June 2012 at 00:21.

Similar Threads

  1. error ISO C++ forbids declaration of 'obj' with no type
    By naturalpsychic in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2011, 06:23
  2. Replies: 2
    Last Post: 10th October 2010, 16:38
  3. Replies: 12
    Last Post: 29th April 2010, 13:22
  4. Error::defined after prior declaration as dllimport:
    By hasnatzaidi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2009, 01:37
  5. Forward Class declaration ERROR
    By nleverin in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2007, 08:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.