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. new connect syntax, signal not found (class from linked library)

new connect syntax, signal not found (class from linked library)

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.0k Views
  • 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.
  • P Offline
    P Offline
    pasiaNos 0
    wrote on last edited by
    #1

    Hi,

    I've a Qt project with:

    a library:

    # .pro
    [...]
    TARGET   = qb_library
    TEMPLATE = lib
    [...]
    

    and the main project:

    # .pro
    [...]
    TARGET = my_program
    TEMPLATE = app
    [...]
    LIBS += -L$$DESTDIR -lqb_library
    INCLUDEPATH += ../qb_library
    DEPENDPATH += ../qb_library
    [...]
    

    In the library project I have this class:

    // .h
    #include <QObject>
    class TestConn3 : public QObject {
            Q_OBJECT
        public:
            explicit TestConn3(QObject *parent = 0);
            void testSignal3Emission();
        signals:
            void testSignal3();
    };
    
    // .cpp
    TestConn3::TestConn3(QObject *parent) : QObject(parent) {}
    
    void TestConn3::testSignal3Emission() {
        emit testSignal3();
    }
    

    and in the program project I have:

    // .h
    #include <QObject>
    class TestCaller : public QObject {
            Q_OBJECT
        public:
            explicit TestCaller(QObject *parent = 0);
        private slots:
            void testSlot();
    };
    
    // .cpp
    #include "testcaller.h"
    
    #include <QDebug>
    #include <testconn3.h>
    
    TestCaller::TestCaller(QObject *parent) : QObject(parent) {
        TestConn3 tc3;
        connect(&tc3, &TestConn3::testSignal3, []() {
            qDebug() << "testSignal3 lambda";
        });
        connect(&tc3, SIGNAL(testSignal3()), SLOT(testSlot()));
        tc3.testSignal3Emission();
    }
    
    void TestCaller::testSlot() {
        qDebug() << "testSignal3 slot";
    }
    

    I simply execute the code with:

    TestCaller tc;
    

    from a MainWindow method.

    The output I get is:

    QObject::connect: signal not found in TestConn3
    testSignal3 slot
    

    So is only the "new syntax" for the connect that's not working.
    I tried to put the TestConn3 class directly inside the program project (simply copied the .h and .cpp file and added to .pro) and the connection with the lambda works fine so I suppose it's something related to the library.

    I'm using Qt 5.4.2 with MinGW 32bit on Windows. (The posted code is only for testing of course. I'm actively developing a quite large project since many years now with around 1k clients around Italy and we could have issues to update the Qt platform so for now I'm sticking with 5.4).

    What I'm doing wrong?

    Thanks!
    (it's my first post here btw so I hope i posted it correctly)

    aha_1980A 1 Reply Last reply
    0
    • P pasiaNos 0

      Hi,

      I've a Qt project with:

      a library:

      # .pro
      [...]
      TARGET   = qb_library
      TEMPLATE = lib
      [...]
      

      and the main project:

      # .pro
      [...]
      TARGET = my_program
      TEMPLATE = app
      [...]
      LIBS += -L$$DESTDIR -lqb_library
      INCLUDEPATH += ../qb_library
      DEPENDPATH += ../qb_library
      [...]
      

      In the library project I have this class:

      // .h
      #include <QObject>
      class TestConn3 : public QObject {
              Q_OBJECT
          public:
              explicit TestConn3(QObject *parent = 0);
              void testSignal3Emission();
          signals:
              void testSignal3();
      };
      
      // .cpp
      TestConn3::TestConn3(QObject *parent) : QObject(parent) {}
      
      void TestConn3::testSignal3Emission() {
          emit testSignal3();
      }
      

      and in the program project I have:

      // .h
      #include <QObject>
      class TestCaller : public QObject {
              Q_OBJECT
          public:
              explicit TestCaller(QObject *parent = 0);
          private slots:
              void testSlot();
      };
      
      // .cpp
      #include "testcaller.h"
      
      #include <QDebug>
      #include <testconn3.h>
      
      TestCaller::TestCaller(QObject *parent) : QObject(parent) {
          TestConn3 tc3;
          connect(&tc3, &TestConn3::testSignal3, []() {
              qDebug() << "testSignal3 lambda";
          });
          connect(&tc3, SIGNAL(testSignal3()), SLOT(testSlot()));
          tc3.testSignal3Emission();
      }
      
      void TestCaller::testSlot() {
          qDebug() << "testSignal3 slot";
      }
      

      I simply execute the code with:

      TestCaller tc;
      

      from a MainWindow method.

      The output I get is:

      QObject::connect: signal not found in TestConn3
      testSignal3 slot
      

      So is only the "new syntax" for the connect that's not working.
      I tried to put the TestConn3 class directly inside the program project (simply copied the .h and .cpp file and added to .pro) and the connection with the lambda works fine so I suppose it's something related to the library.

      I'm using Qt 5.4.2 with MinGW 32bit on Windows. (The posted code is only for testing of course. I'm actively developing a quite large project since many years now with around 1k clients around Italy and we could have issues to update the Qt platform so for now I'm sticking with 5.4).

      What I'm doing wrong?

      Thanks!
      (it's my first post here btw so I hope i posted it correctly)

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @pasiaNos-0

      The output I get is:
      QObject::connect: signal not found in TestConn3
      testSignal3 slot

      This is at runtime, correct?

      Then it cannot be from the new syntax. The new syntax generates compiler errors. Only the old syntax is evaluated at runtime and generates such messages.

      Regards

      Qt has to stay free or it will die.

      Christian EhrlicherC P 2 Replies Last reply
      1
      • aha_1980A aha_1980

        Hi @pasiaNos-0

        The output I get is:
        QObject::connect: signal not found in TestConn3
        testSignal3 slot

        This is at runtime, correct?

        Then it cannot be from the new syntax. The new syntax generates compiler errors. Only the old syntax is evaluated at runtime and generates such messages.

        Regards

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #3

        @aha_1980 said in new connect syntax, signal not found (class from linked library):

        Then it cannot be from the new syntax.

        It can, see QObject::connectImpl(). I would guess the problem comes from the fact that the class is not exported - but the I wonder how the code above should work at all then...

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • aha_1980A aha_1980

          Hi @pasiaNos-0

          The output I get is:
          QObject::connect: signal not found in TestConn3
          testSignal3 slot

          This is at runtime, correct?

          Then it cannot be from the new syntax. The new syntax generates compiler errors. Only the old syntax is evaluated at runtime and generates such messages.

          Regards

          P Offline
          P Offline
          pasiaNos 0
          wrote on last edited by
          #4

          @aha_1980 @Christian-Ehrlicher

          Yes it is the runtime output.

          In any case, in the production code I have the project set up with the main project (with subdirs with .pri files) and the external library like in the example and it has always worked (with old syntax connections). For a new functionality I was testing the lambda connection and I came across this problem. For what I need I can workaround the issue with a callback contained in a container object inside a QVariant and setting it to a property of the sender object then in the receiver slot I get back the property and invoke the callback. I've done some tests today and it's working but the lambda connection would be much better and anyway at this point I want to understand why it's not working.

          It could be something related to the combination of Qt version and compiler?

          Anyway I'll return to work on next monday so this weekend I can't do much testing.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            I would suggest you to create a minimal, compilable example and submit a bug report so the developer can take a look on it. There is a similar bug for msvc around: https://bugreports.qt.io/browse/QTBUG-79570

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            P 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              I would suggest you to create a minimal, compilable example and submit a bug report so the developer can take a look on it. There is a similar bug for msvc around: https://bugreports.qt.io/browse/QTBUG-79570

              P Offline
              P Offline
              pasiaNos 0
              wrote on last edited by
              #6

              @Christian-Ehrlicher
              Ok, thanks, on monday I'll proceed as suggested.

              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