简体   繁体   English

传递给qt插件的对象的调用方法产生符号查找错误

[英]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".这个“问题”有两种解决方案。

  • Make shared library - make shared library and move code that application and QtPlugin use into that library创建共享库- 创建共享库并将应用程序和 QtPlugin 使用的代码移动到该库中
  • 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添加用于 QMake 文件的文件的 .h 和 .cpp - QtPlugin 中使用的应用程序的头文件和源文件添加到 .pro 文件中的 HEADERS 和 SOURCES 指令 - 这实际上是静态链接

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.

相关问题 从共享库中使用我的Qt插件时出现符号查找错误 - symbol lookup error when using my Qt plugin from inside of shared library QT项目中的符号查找错误问题 - Symbol lookup error problem in QT project C ++方法指针调用会产生未定义的符号错误? - C++ method pointer call yields undefined symbol error? Qt:Centos 6.7中的会话管理错误和符号查找错误 - Qt: Session management error and Symbol lookup error in Centos 6.7 在NPAPI插件对象上调用方法会重生该插件 - Calling a method on NPAPI plugin object respawns the plugin 在JS中对C ++单例对象的调用方法会产生“ TypeError:对象[object Object]的属性&#39;foo&#39;不是函数” - Calling method on C++ singleton object in JS yields “TypeError: Property 'foo' of object [object Object] is not a function” Qt,库函数调用给出了未解决的外部符号错误 - Qt, Library function calling gives unresolved external symbol error 与 Qt 交叉编译到 Raspberry Pi 3B+ 地址簿(协议缓冲区) - 错误符号查找错误 - Cross-compile with Qt to Raspberry Pi 3B+ the addressbook (Protocol Buffer) - error symbol lookup error 部署后的Linux qt应用程序-符号查找错误:libQt5Core.so.5未定义符号:uncv_getDefaultName_56 - Linux qt application after deployment - symbol lookup error: libQt5Core.so.5 undfined symbol: uncv_getDefaultName_56 错误:在 LLDB 中调用 stl 方法时无法查找符号 - Error: Couldn't lookup symbols when calling an stl method in LLDB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM