[英]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.我在将对象传递给 Qt 插件时遇到问题,当尝试使用 const 成员函数获取其成员时,出现符号查找错误。 Example:例子:
This is inside Qt application:这是在 Qt 应用程序中:
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:这是在 QtPlugin 中:
plugin.h插件.h
#include "a.h"
#include "b.h"
#include "c.h"
//....
plugin.cpp插件.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:如果我从插件的 Qt 应用程序 somefunc() 调用,我会收到符号查找错误:
symbol lookup error ... plugin.so undefined symbol _ZNK5b6a
but if I put B and C class members into public domain it works using:但是如果我将 B 和 C 类成员放入公共域,它可以使用:
qDebug() << c->m_b->m_a->count();
Did anyone have similar problem or knows how to solve this?有没有人有类似的问题或知道如何解决这个问题? Thanks.谢谢。
Class members are private by default.默认情况下,类成员是私有的。 B::a()
and C::b()
are private. B::a()
和C::b()
是私有的。 To be able to call these member functions from Plugin::somefunc()
you need to make them public explicitly.为了能够从Plugin::somefunc()
调用这些成员函数,您需要明确地将它们设为 public。
There are two solutions to this "problem".这个“问题”有两种解决方案。
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.此答案供将来参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.