[PyKDE] Re: PyQt ActiveX support: can't pass some types of
parameters
Mike Thompson
mike.spam.filter at day8.com.au
Tue Oct 12 08:00:09 BST 2004
Mike Thompson wrote:
> Mike Thompson wrote:
>
>>
>> I'm trying to manipulate ActiveX objects using pyQt, but I've hit the
>> following brick wall:
>>
Arrggh. Still problems ...
I'm now getting no error messages. Which was very encouraging
initially, BUT I've had to take a couple of steps back because
dynamicCall does not work for me. (Don't even start me on "property()")
I MUST be doing something wrong. And it must be horribly obvious, but
its invisible to me.
I have a small enough example:
#-------------------------------------------------------------------------
import qt
import qtaxcontainer
streamObj = qtaxcontainer.QAxObject("ADODB.Stream")
streamObj.dynamicCall("Open()");
streamObj.dynamicCall("WriteText(QString&)", qt.QVariant("some text"));
streamObj.dynamicCall( "SaveToFile(QString&)", qt.QVariant("pyQt.out"))
#-------------------------------------------------------------------------
When I run this script, there is no output file 'pyQt.out'.
On the other hand, the following (seemingly identical) win32com based
code works:
import win32com.client
streamObj = win32com.client.Dispatch("ADODB.Stream")
streamObj.Open()
streamObj.WriteText("some text")
streamObj.SaveToFile("win32com.out")
#-------------------------------------------------------------------------
So I wondered if I was using the right method signatures in
dynamicCall(). To check, I tried the following:
import qt
import qtaxcontainer
streamObj = qtaxcontainer.QAxObject("ADODB.Stream")
print streamObj.generateDocumentation()
but to my surprise nothing is printed (empty string).
Maybe its because I'm using QAxObject insted of QAxWidget? I change my
script to ...
import qt
import qtaxcontainer
streamObj = qtaxcontainer.QAxWidget("ADODB.Stream")
print streamObj.generateDocumentation()
But that fails with
"QPaintDevice: Must construct a QApplication before a QPaintDevice"
So I change the script to:
import qt
import qtaxcontainer
a = qt.QApplication([]) # this line added
streamObj = qtaxcontainer.QAxWidget("ADODB.Stream")
print streamObj.generateDocumentation()
which works!! I have output.
Ahhh. I notice that methods like Open() have a very different
prototype to that which I used above. I can almost smell
success now. I change script to:
import qt
import qtaxcontainer
streamObj = qtaxcontainer.QAxObject("ADODB.Stream")
streamObj.dynamicCall("Open(const
QVariant&,ConnectModeEnum,StreamOpenOptionsEnum,const QString&,const
QString&)");
streamObj.dynamicCall("WriteText(const QString&,StreamWriteEnum)",
qt.QVariant("some text"));
streamObj.dynamicCall( "SaveToFile(const
QString&,SaveOptionsEnum)", qt.QVariant("pyQt.out"))
Still doesn't work. No errors again but still no 'pyQt.out' file created.
dynamicCall() must be failing silently somewhere. I hate that.
Perhaps its because I'm not suppling exactly the right number of
parameters to the methods. Perhaps the default parameter values are not
being used when I don't supply them.
I try this next ... but I'm out of time right now.
If anyone knows about all this, please feel free to jump in a tell me
how to get it going.
Other than that, I'm sending this post as a record of progress. Perhaps
Google will show it up for someone else later and save them the journey.
--
Mike
More information about the PyQt
mailing list