Author Archive

Qt调用ActiveX控件的两个问题

Qt使用ActiveX控件的方法这里不再介绍,具体请参考:
http://blog.csdn.net/tingsking18/archive/2010/03/22/5403038.aspx
问题1:
通过Qt调用ActiveX控件,一般是把IDispatch*或者是IKnown* 封装成QAxObject,然后再调用
querySubObject或者dynamicCall方法。但是当调用dynamicCall方法的时候需要传入一个
IDispatch*或者是IKnown*的时候我们该怎么办呢?可以调用QAxObject的asVariant()方法,
将这个COM对象装换为QVariant。例如:
SetSourceData函数的原型是:
void SetSourceData(Range^ Source, Object^ PlotBy);
我们要这样调用:
QAxObject * range = worksheet->querySubObject("Range(\"A1:H1\")");
activeChart->dynamicCall("SetSourceData(QAxObject*,int)",range->asVariant(),1);
问题2:
除了使用QAxObject方法来调用ActiveX还有什么其他的办法么?QAxObject使用起来太麻烦了。
       如果不想这样做还可以QAxWidget还为我们提供了QueryInterface方法,和用VC调用基本差不多了。
例如:
IWebBrowser2 *webBrowser = 0;
activeX->queryInterface(IID_IWebBrowser2, (void *)&webBrowser);
if (webBrowser)
{
     webBrowser->Navigate2(pvarURL);
     webBrowser->Release();
}
 

Read More...

Tags: ,
Posted on August 2nd, 2010 in Qt技术 | 2 Comments ».

Qt程序只运行一个实例

在我的这篇文章中使Qt程序只运行一个实例,通过QSharedMemory来实现进程间通讯,使用这种方式来是Qt程序只运行一个实例。有一天测试部的MM告诉我,她在测试的时候,程序crash掉了,再次运行程序,程序不能继续运行。
程序不能运行,显然是共享内存没有释放引起的,但是程序crash后为什么共享内存不能释放呢?于是打开Qt助手看到QSharedMemory是这样解释的:
Unix: QSharedMemory "owns" the shared memory segment. When the last thread or process that has an instance of QSharedMemory attached to a particular shared memory segment detaches from the segment by destroying its instance of QSharedMemory, the Unix kernel release the shared memory segment. But if that last thread or process crashes without running the [...]

Read More...

Tags:
Posted on July 16th, 2010 in Qt技术 | 1 Comment ».