• 4504阅读
  • 3回复

如何在次线程中使用COM(我用QAxObject操作word文档) [复制链接]

上一主题 下一主题
离线neohunter
 

只看楼主 倒序阅读 楼主  发表于: 2016-04-26
void MyThread::run(){  
    CoInitialize(NULL);

    QAxWidget *word=new QAxWidget("Word.Application", 0, Qt::MSWindowsOwnDC);
    QAxObject * documents = word->querySubObject("Documents");
    documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("E:/temple/cover.doc"));
    QAxObject *document=word->querySubObject("ActiveDocument");
   // 文件另存为docbyqt.doc,关闭工作文档,退出应用程序  
    document->dynamicCall("SaveAs (const QString&)", QString("E:/1/0.封面.doc"));  
    document->dynamicCall("Close (boolean)", false);   word->dynamicCall("Quit()");  

    CoUninitialize();
}
我使用了  CoInitialize(NULL)和CoUninitialize()为什么在运行的时候还是报错。
void MainWindow::on_pushButton_clicked(){    MyThread = new MyThread(this);    MyThread->start(QThread::LowestPriority);}错误信息如下:
ASSERT failure in QWidget: "Widgets must be created in the GUI thread.", file [url]kernel\qwidget.cpp, line 1133[/url]
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
QObject::~QObject: Timers cannot be stopped from another thread
离线dbzhang800

只看该作者 1楼 发表于: 2016-04-26
QWidget及其派生类只能在主线程使用!
离线neohunter

只看该作者 2楼 发表于: 2016-04-26
请问有什么方法能够让这些耗时的操作不卡死界面啊?谢谢你的解答
离线neohunter

只看该作者 3楼 发表于: 2016-04-26
回 dbzhang800 的帖子
dbzhang800:QWidget及其派生类只能在主线程使用! (2016-04-26 12:04) 

请问有什么方法能够让这些耗时的操作不卡死界面啊?谢谢你的解答
快速回复
限100 字节
 
上一个 下一个