PDA

View Full Version : ActiveQT (QAxObject) questions



semajnosnibor
9th January 2012, 22:18
I've run into a couple of problems working with QAxObjects:
1) I can't figure out how to access the 'member constants' of a QAxObject. I've dumped out (specifically accessing Excel). I've run the generateDocumentation() on my QAxObject, and I can see all the constants and their values, however I'm not sure how to actually query their value at run-time (in case they differ from version to version of excel say). Below are a few methods I've tried:

QAxObject *excel = new QAxObject("Excel.Application",0);
//attempt 1
int num = excel->property("xlAll").toInt(); //from documentation, should have value of -4104
//attempt 2
int num = excel->querySubObject("xlAll").asVariant().toInt()

2) How do you pass an ignored value to a function when calling '->querySubObject()'? Some functions will have optional parameters, but will expect a void value for any parameters you wish to ignore. A specific example is below:
For excel, if you want to add a worksheet to the end of the list of sheets, you call 'add(QVariant before, QVariant after)', where the before should be null if you want to use the 'after'. Apparently in C# you would use a value of 'Type.Missing', however I can not find the equivalent with QVariant.

Thanks.

stampede
10th January 2012, 09:23
I don't know about 1), but for 2) - have you tried to use an invalid QVariant (QVariant()) ?

semajnosnibor
10th January 2012, 14:43
Yep, tried that as it seemed the logical step. However the QAxBase throws up an error:

QAxBase: Error calling IDispatch member Add: Exception thrown by server
Code : 1004
Source : Microsoft Office Excel
Description: Unable to get the Add property of the Sheets class
Help : C:\Program Files (x86)\Microsoft Office\Office12\1033\XLMAIN11.CHM
Connect to the exception(int,QString,QString,QString) signal to catch this exception

semajnosnibor
19th January 2012, 17:15
Found a work around to access the 'Constants'. Ended up just making a function which strips out the constants from the QAxObject (thru the 'generateDocumenation') and stores them in a QHash. Not super elegant, but workable, and a lot faster then I originally thought it would be. Of course it is prone to having issues in future releases of QT, if they for some reason change the formatting that 'generateDocumentation' produces.

As for making a default parameter... so far no dice. Seems strange that no-one has used ActiveQT and a member function which requires the use of a 'Type.Missing' variant as a place holder. So far I've managed to work around it, but again not the prettiest solution. For instance if you want to add a worksheet onto the end of a workbook, you have to call 'Add(before,after)', where 'before' would be the sheet to insert before (use a 'Type.Missing' variant if you will use the 'after' item), and 'after' would be the sheet to add it after. Basically I had to duplicate the last sheet (puts a copy before the last sheet), then run the add sheet passing the last sheet (which puts the new sheet before the last sheet), then finally remove the last sheet. Works, but it is sure a lot more steps!