Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Linker error for signal declaration .
Forum Updated to NodeBB v4.3 + New Features

Linker error for signal declaration .

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 6.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BibekKumar
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        Hi BibekKumar,

        SIGNAL should not be used in this way, and it shouldn't have a return value.

        Regards,

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raaghuu
          wrote on last edited by
          #4

          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 :) )

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mario84
            wrote on last edited by
            #5

            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"

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved