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. QObject::connect: signal not found in
Forum Updated to NodeBB v4.3 + New Features

QObject::connect: signal not found in

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 161 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.
  • V Offline
    V Offline
    Victorusik
    wrote on last edited by
    #1

    Problem with signals in dynamic libraries.

    When I use mylib SHARED an error qt.core.qobject.connect: QObject::connect: signal not found in TestLib occure.

    But if mylib STATIC it works correctly

    Why can't connect() find signal if it's in dll lybrary?


    Below: CMakeLists.txt, mainwindow.cpp, testlib.h, testlib.cpp

    // CMakeLists.txt
    qt_add_library(mylib SHARED
            testlib.cpp
            testlib.h
    )
    
    target_link_libraries(mylib
            PUBLIC
            Qt6::Core
    )
    
    qt_add_executable(main main.cpp
            mainwindow.cpp
            mainwindow.h
    )
    
    target_link_libraries(main PRIVATE
            Qt6::Core
            Qt6::Widgets
            mylib
    )
    
    // mainwindow.cpp
    MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent), lib(new TestLib)
     {
        bool connected = connect(lib, &TestLib::testSignal, this, []() {
            qDebug() << "Test Signal";
        });
        // If mylib SHARED -> error
        // If mylib STATIC -> Test Signal appears in console
        lib->interaptSig();
    }
    
    // testlib.h
    #ifndef TESTLIB_H
    #define TESTLIB_H
    
    #include <QObject>
    
    class TestLib : public QObject {
        Q_OBJECT
    
    signals:
        void testSignal();
    
    public:
        TestLib(QObject *parent = nullptr);
    
        void interaptSig();
    };
    #endif //TESTLIB_H
    
    // testlib.cpp
    #include "testlib.h"
    
    
    TestLib::TestLib(QObject *parent) : QObject(parent) {}
    
    void TestLib::interaptSig() {
        emit testSignal();
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      When you're on windows you forgot to export the class.

      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
      5
      • V Victorusik has marked this topic as solved on

      • Login

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