crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

> Запуск QAxObject в другом потоке
Алексей
  опции профиля:
сообщение 30.3.2011, 18:55
Сообщение #1


Студент
*

Группа: Участник
Сообщений: 37
Регистрация: 29.8.2010
Пользователь №: 1988

Спасибо сказали: 0 раз(а)




Репутация:   0  


Пытаюсь инициализировать COM-объект в другом потоке, Для этого использую класс TestConnector
testconnector.h
#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
testconnector.cpp
#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 должно быть только в главном потоке.
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Сообщений в этой теме


Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0




RSS Текстовая версия Сейчас: 23.4.2024, 13:12