gpt4 book ai didi

c++ - 使用 QLibrary 加载库

转载 作者:行者123 更新时间:2023-11-30 05:11:19 25 4
gpt4 key购买 nike

我发现了以下用于在 Qt 中加载库的代码,但我不完全理解它是如何工作的。有人能给我解释一下吗:typedef int (*MyPrototype)(int, int);?

int r1 = 0;
QLibrary library("mathlib.so");
if (!library.load())
out << library.errorString() << endl;
if (library.load())
out << "library loaded" << endl;

typedef int (*MyPrototype)(int, int);

MyPrototype myFunction = (MyPrototype)library.resolve("add");
if (myFunction)
r1 = myFunction(a,b);
else
out << library.errorString() << endl;

最佳答案

so或者dll有函数,我们要用,怎么调用

int add(int in_iParam1, int in_iParam2)

定义函数类型

typedef int (*MyPrototype)(int, int);

在so文件中寻找'add'函数

MyPrototype myFunction = (MyPrototype)library.resolve("add");

使用参数 'a' 和 'b' 调用函数 'add' 并将结果传给 'r1'

r1 = myFunction(a,b);

关于c++ - 使用 QLibrary 加载库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45119131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com