edin-m
edin-m

Reputation: 3121

Calling method of object passed to qt plugin yields symbol lookup error

I have a problem with passing a object to Qt Plugin and when trying to get its member using const member function i get symbol lookup error. Example:

This is inside Qt application:

class A{
    int a,b,c;
}; 

class B{
public:
    const QList<A*>* a() const { return m_a; }
private:
    QList<A*>* m_a;
};

class C{
public:
    const B* b() const { return m_b; }
private:
    B* m_b;
};

This is inside QtPlugin:

plugin.h

#include "a.h"
#include "b.h"
#include "c.h"

//....

plugin.cpp

void Plugin::somefunc(C* c)
{
    qDebug() << c->b()->a()->count();
}

If I call from Qt application somefunc() of a plugin I get symbol lookup error:

symbol lookup error ... plugin.so undefined symbol _ZNK5b6a

but if I put B and C class members into public domain it works using:

    qDebug() << c->m_b->m_a->count();

Did anyone have similar problem or knows how to solve this? Thanks.

Upvotes: 1

Views: 780

Answers (2)

edin-m
edin-m

Reputation: 3121

There are two solutions to this "problem".

  • Make shared library - make shared library and move code that application and QtPlugin use into that library
  • Add .h and .cpp of files used to QMake file - header and source files of application used in QtPlugin add to HEADERS and SOURCES directive in .pro file - this is actually static linking

I haven't found similar question on web, and thus putting this answer. Maybe question was fuzzy, sorry about that. Thanks for answer. This answer is for any future reference.

Upvotes: 1

Oswald
Oswald

Reputation: 31647

Class members are private by default. B::a() and C::b() are private. To be able to call these member functions from Plugin::somefunc() you need to make them public explicitly.

Upvotes: 1

Related Questions