QLibrary解决方案返回false [英] QLibrary resolve returns false

查看:1473
本文介绍了QLibrary解决方案返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动态地包含类文件,并通过加载.dll到QLibrary选择这样做。我现在的问题是,当我尝试调用resolve() - 方法,它返回0。

I´m trying to include classfiles dynamically right now and chose to do so by loading the .dll into a QLibrary. The problem I´m having now is, that when I try to call the resolve()-method it returns 0.

编辑:
在此期间问题已经解决,我决定编辑代码,所以其他人可以看到它的工作原理:

In the meantime the problem has been solved and I decided to edit the code, so others can see how it works:

这是.dll的头文件:

#ifndef DIVFIXTURE_H
#define DIVFIXTURE_H

#include<QObject>
#include<QVariant>

class __declspec(dllexport) DivFixture : public QObject
{
    Q_OBJECT
public:
    Q_INVOKABLE DivFixture();
    Q_INVOKABLE void setNumerator(QVariant num);
    Q_INVOKABLE void setDenominator(QVariant denom);
    Q_INVOKABLE QVariant quotient();

private:
    double numerator, denominator;
};

#endif

这是dll的.cpp -file:

#include "testfixture.h"

DivFixture::DivFixture(){}

void DivFixture::setNumerator(QVariant num)
{
    numerator=num.toDouble();
}


void DivFixture::setDenominator(QVariant denom)
{
    denominator=denom.toDouble();
}


QVariant DivFixture::quotient()
{
    QVariant ret;
    ret=numerator/denominator;
    return ret;
}

//non-class function to return pointer to class
extern "C" __declspec(dllexport) DivFixture* create()
{
   return new DivFixture();
}

这是我如何加载我的类:

currentFixture.setFileName("C:\\somepath\\testFixture.dll");
if(currentFixture.load());
{
    typedef QObject* (*getCurrentFixture)();
    getCurrentFixture fixture=(getCurrentFixture)currentFixture.resolve("create");
    if (fixture)
    {
        Fixture=fixture();
    }
}


推荐答案

需要使用 __declspec(dllexport)

class __declspec(dllexport) DivFixture : public QObject
{

这篇关于QLibrary解决方案返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆