1

在 Qt 中,我的 Dll 有问题。在我的 dll 中,我有一个从 dll 内部发出的信号。在另一个我的测试应用程序中,我用 Qliberary 加载我的 dll 并且没有问题。我已经导出了我的 dll 函数,我可以在我的测试项目中毫无问题地调用它们。但我无法将我的 dll 信号连接到我的测试应用程序中的测试应用程序的插槽中。它得到这个错误:QObject::connect: No such signal QLibrary::dllsignal()。

我的 dll.cpp

#include "qtmfcbrooks.h"


QtMfcBrooks::QtMfcBrooks()
{
    qDebug()<<"loading QtMfcBrooks ...";
    //donot send any signal or call other functions
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(slotTest()));
    timer->start(2000);
}

void QtMfcBrooks::slotTest(QString)
{
    emit sigTest("This signal is emitted from dll at"+QDateTime::currentDateTime().toString());
}

void QtMfcBrooks::slotTestMain(QString str)
{
    qDebug()<<str;
}

void QtMfcBrooks::slotTestPublic()
{
    qDebug()<<"slotTestPublic at"+QDateTime::currentDateTime().toString();
}

dll.h

#ifndef QTMFCBROOKS_H
#define QTMFCBROOKS_H


#include <QByteArray>
#include <math.h>
#include <QTimer>
#include <QtCore/qglobal.h>


#if defined(QTMFCBROOKS_LIBRARY)
#  define QTMFCBROOKSSHARED_EXPORT Q_DECL_EXPORT
#else
#  define QTMFCBROOKSSHARED_EXPORT Q_DECL_IMPORT
#endif


class QTMFCBROOKSSHARED_EXPORT QtMfcBrooks :public QObject
{
    Q_OBJECT

public:

    QtMfcBrooks();

signals:
       void sigTest(QString);
private:


    public slots:
         void slotTest(QString);
         void slotTestPublic();
         void slotTestMain(QString str);

private:

     QTimer * timer;
};

extern "C" {
   QTMFCBROOKSSHARED_EXPORT void testPublic();
   QTMFCBROOKSSHARED_EXPORT int main();
   QTMFCBROOKSSHARED_EXPORT void slotTestGlobal(QString);
}

#endif // QTMFCBROOKS_H

dll_global.cpp

#include <QApplication>
#include "qtmfcbrooks.h"

QtMfcBrooks * accessclass;

int main()
{
    qDebug()<<"loading main ...";
    if(accessclass) delete accessclass;
    accessclass = new QtMfcBrooks();

}

void testPublic()
{
    qDebug()<<"loading testPublic ...";
    accessclass->slotTestPublic();
}

void slotTestGlobal(QString msg)
{
    accessclass->slotTestMain(msg);
}

我的 test.cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    this->qtmfcbrooks = new  QLibrary ("QtMfcBrooks");

    if (!qtmfcbrooks->load()) qDebug()<<qtmfcbrooks->errorString()<<QDateTime::currentDateTime();
    else {
        qDebug() << "Liberary is loaded";        
        connect(qtmfcbrooks,SIGNAL(sigTest(QString)),this->ui->label,SLOT(setText(QString)));
   }
    testMain();
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::testMain()
{
    if(qtmfcbrooks && qtmfcbrooks->isLoaded()){
        typedef int (*f)(void);
        f func = (f) qtmfcbrooks->resolve("main");
        if (func){
            func();
            return;
        }else
            qDebug() <<"can not resolve "<<"main";
    }
}

我应该怎么办?

4

0 回答 0