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. [Solved] qobject_cast fails when accessed across DLL boundaries.
Forum Updated to NodeBB v4.3 + New Features

[Solved] qobject_cast fails when accessed across DLL boundaries.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.3k 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.
  • G Offline
    G Offline
    greenaj
    wrote on last edited by
    #1

    I defined a simple class in a static lib shared between a plugin and a host exe. Yes, the class derives from QObject has the Q_OBJECT macro and all of that. It's used in a publish / subscribe feature defined in a static lib that forms a generic communication method between an app and plugins.

    What I have noticed is that qobject_cast in the exe works for instances create in the exe bug not for instances created in a plugin. qobject_cast will also work in the plugin for classes instantiated there. Instances going across the plugin to the exe fail for qobject_cast, but work for dynamic_cast.

    Is qobject_cast supposed to not work when used for class instances instantiated across DLL boundaries?

    Thanks,
    greenaj

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Lets call your QObject derived class MyObject.

      Your current problem is not the dll boundaries, it's your static library. Each element of your project that links to that static library will have it's own copy of your MyObject class. This means that you will have multiple copies of the static meta object associated to your class thus qobject_cast will fail since it will check the plugin MyObject staticMetaObject against the application MyObject staticMetaObject. IIRC using gcc there's a workaround for that. But the simple and straight forward way is to keep your common code in a shared library

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • G Offline
        G Offline
        greenaj
        wrote on last edited by
        #3

        I came across an old thread that said the same or similar to what you just said. I have since moved the QObject derived class into a shared DLL and qobject_cast seems to now be working across DLL boundaries.

        Thanks for your reply which is the answer to this problem.

        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