Пытаюсь инициализировать COM-объект в другом потоке, Для этого использую класс TestConnector
#ifndef TESTCONNECTOR_H
#define TESTCONNECTOR_H
#include <ActiveQt/qaxobject.h>
#include <ActiveQt/qaxbase.h>
#include <QThreadPool>
#include <QObject>
class TestConnector : public QObject, public QRunnable
{
Q_OBJECT
public:
TestConnector(QThread *recieveThread);
void run();
void setRecieveThread(QThread *t);
signals:
void testConnectionFailed();
void testConnected(QAxObject *ax);
protected:
QThread *recieveThread;
};
#endif // TESTCONNECTOR_H
#include "testconnector.h"
#include <QDebug>
TestConnector::TestConnector(QThread *recieveThread) :
QObject(0)
{
setRecieveThread(recieveThread);
}
void TestConnector::setRecieveThread(QThread *t)
{
this->recieveThread = t;
}
void TestConnector::run()
{
qDebug("TestConnector: Connecting to Ax");
QAxObject *ax = new QAxObject("Word.Application", 0);
if(ax->isNull())
{
qCritical("TestConnector: Ax connection failed");
delete ax;
ax = 0;
emit testConnectionFailed();
}
else
{
qDebug("TestConnector: Ax connected successfully");
ax->moveToThread(recieveThread);
emit testConnected(ax);
}
}
Запускаю:
TestConnector *tc = new TestConnector(this->thread());
connect(tc, SIGNAL(testConnected(QAxObject*)), this, SLOT(testConnected(QAxObject*)));
connect(tc, SIGNAL(testConnectionFailed()), this, SLOT(testConnectionFailed()));
QThreadPool::globalInstance()->start(tc);
Получаю
(Info) TestConnector: Connecting to Ax
(Warning) QAxBase::setControl: requested control Word.Application could not be instantiated
(Error) TestConnector: Ax connection failed
В основном потоке QAxObject *ax = new QAxObject("Word.Application", 0); выполняется без ошибок. Вроде в документации нигде не написано, что QAxObject должно быть только в главном потоке.