Thanks for your advices so far.
I digged into this thing a little bit further and stumbled across a really strange behaviour. For now I'm able to instantiate my QAxObject in a new thread. But only if accessed it from the main thread before.
The following code works fine but commenting out test() in main() will deliver an error that the control could not be instantiated. I'm getting a little confused now, since I can't find anything about that in the docs. Could someone please lead me in the right direction?
public:
protected:
void run();
private:
void process();
};
moveToThread(this);
}
void MyThread::process() {
qDebug() << thread() << "accessing";
comObj->setControl("{CLASSID_HERE}");
::CoInitialize(comObj);
}
void MyThread::run() {
process();
}
void test() {
qDebug() << qApp->thread() << "accessing";
comObj->setControl("{CLASSID_HERE}");
CoInitialize(comObj);
QVariantList params = QVariantList();
params.append("D:\\path\\to\\file");
comObj->dynamicCall("openFile(QString)", params);
delete comObj;
}
int main(int argc, char* argv[]) {
test();
MyThread *mt = new MyThread();
mt->start();
return a.exec();
}
class MyThread : public QThread {
public:
MyThread(QObject *parent = 0);
protected:
void run();
private:
void process();
};
MyThread::MyThread(QObject *parent) : QThread(parent) {
moveToThread(this);
}
void MyThread::process() {
qDebug() << thread() << "accessing";
QAxObject *comObj = new QAxObject();
comObj->setControl("{CLASSID_HERE}");
::CoInitialize(comObj);
}
void MyThread::run() {
process();
}
void test() {
QAxObject *comObj = new QAxObject();
qDebug() << qApp->thread() << "accessing";
comObj->setControl("{CLASSID_HERE}");
CoInitialize(comObj);
QVariantList params = QVariantList();
params.append("D:\\path\\to\\file");
comObj->dynamicCall("openFile(QString)", params);
delete comObj;
}
int main(int argc, char* argv[]) {
QApplication a(argc, argv);
test();
MyThread *mt = new MyThread();
mt->start();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks