0
假設一個對象在線程中運行。它有一個指向QAxObject實例和對象B的指針。對象B具有指向QAxObject的指針。在兩個線程之間共享QAxObject?
對象A創建一個線程並在其中移動對象B.
#ifndef OBJECTA_H
#define OBJECTA_H
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <QAxObject>
#include "ObjectB.h"
class ObjectA : public QObject
{
Q_OBJECT
public:
ObjectA(QObject *parent = 0) : QObject(parent)
{
thread = new QThread();
activeX = new QAxObject();
objectB = new ObjectB(activeX);
objectB->moveToThread(thread);
ObjectA::connect(objectB, SIGNAL(someSignal()), this, SLOT(someSlot()));
thread->start();
}
protected slots:
void someSlot();
private:
QThread *thread;
QAxObject *activeX;
ObjectB *objectB;
};
#endif // OBJECTA_H
#ifndef OBJECTB_H
#define OBJECTB_H
#include <QtCore/QObject>
#include <QAxObject>
class ObjectB : public QObject
{
Q_OBJECT
public:
ObjectB(QAxObject *axObject, QObject *parent = 0) : QObject(parent)
{
activeX = axObject;
}
signals:
void someSignal();
private:
QAxObject *activeX;
};
#endif // OBJECTB_H
對象B是否能夠與對象A共享的QAxObject一起工作?
我覺得這是不可能的。目前,我有這個錯誤:QAxBase: Error calling IDispatch member NewProject: Unknown error
。
線程A和線程B都不能使用QAxObject。
有關這方面的任何信息?