QAxObject - transfer code from vba to qt
-
Hi,
I try understand COM (Component Object Model) using qt.
Anyone of forumers can help me transfer below .VBA example to qt code ? :Dim oGT Set oGT = CreateObject("InsERT.GT") oGT.Produkt = 1 oGT.Wczytaj("C:\ProgramData\InsERT\InsERT GT\Subiekt2.xml") Set oSubiekt = oGT.Uruchom(0, 0)I begin from below code:
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QAxObject *oGT = new QAxObject("InsERT.gt"); }and I do not know what to do next.
-
Hi,
I try understand COM (Component Object Model) using qt.
Anyone of forumers can help me transfer below .VBA example to qt code ? :Dim oGT Set oGT = CreateObject("InsERT.GT") oGT.Produkt = 1 oGT.Wczytaj("C:\ProgramData\InsERT\InsERT GT\Subiekt2.xml") Set oSubiekt = oGT.Uruchom(0, 0)I begin from below code:
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QAxObject *oGT = new QAxObject("InsERT.gt"); }and I do not know what to do next.
@Damian7546
You should look around for examples, start by Googling forQAxObjectand look at some of the hits, e.g. I answered this in https://forum.qt.io/topic/118744/how-to-use-qaxobject-in-qt.Something like https://forum.qt.io/topic/128566/qaxobject-excel shows how you might make a couple of calls. E.g. for
oGT.Uruchom(0, 0)I think it would beoGT->dynamicCall("Uruchom(int, int)", 0, 0) // or QAxObject* value = oGT->querySubObject("Uruchom(int, int)", 0, 0) -
@Damian7546
Not surprising since"C:\ProgramData\InsERT\InsERT GT\Subiekt2.xml"is not a legitimate C++ string literal, or at least does not produce what you think it produces.... -
ok, it seems to be working:
QAxObject *oGT = new QAxObject("InsERT.gt"); oGT->setProperty("Produkt", 1); oGT->dynamicCall("Wczytaj(string)", "C:\\ProgramData\\InsERT\\InsERT GT\\Subiekt2.xml"); QAxObject *oSubiekt = oGT->querySubObject("Uruchom(int, int)", 0, 0); -
D Damian7546 has marked this topic as solved on
-
Still problems:
Below part of code in .VBA:
oSubGT.Okno.Widoczne = False Set oSubDok = oSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA) Set oSubPoz = oSubDok.Pozycje.Dodaj(23) oSubPoz.IloscJm = 13 oSubPoz.WartoscBruttoPoRabacie = 1000And below transfered to qt C++:
QAxObject *Okno = oSubGT->querySubObject("Okno"); Okno->setProperty("Widoczne", false); QAxObject* oSubDok = oSubGT->querySubObject("Dokumenty"); oSubDok->dynamicCall("Dodaj(int)",0xFFFFFFF7); //gtaSubiektDokumentPA=0xFFFFFFF7 QAxObject* oSubPoz = oSubDok->querySubObject("Pozycje"); oSubPoz->dynamicCall("Dodaj(int)", 24); oSubPoz->setProperty("IloscJm", 13); oSubPoz->setProperty("WartoscBruttoPoRabacie", 1000);but something went wrong:
QAxBase::dynamicCallHelper: Pozycje: No such property in [unknown]
Candidates are: -
Still problems:
Below part of code in .VBA:
oSubGT.Okno.Widoczne = False Set oSubDok = oSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA) Set oSubPoz = oSubDok.Pozycje.Dodaj(23) oSubPoz.IloscJm = 13 oSubPoz.WartoscBruttoPoRabacie = 1000And below transfered to qt C++:
QAxObject *Okno = oSubGT->querySubObject("Okno"); Okno->setProperty("Widoczne", false); QAxObject* oSubDok = oSubGT->querySubObject("Dokumenty"); oSubDok->dynamicCall("Dodaj(int)",0xFFFFFFF7); //gtaSubiektDokumentPA=0xFFFFFFF7 QAxObject* oSubPoz = oSubDok->querySubObject("Pozycje"); oSubPoz->dynamicCall("Dodaj(int)", 24); oSubPoz->setProperty("IloscJm", 13); oSubPoz->setProperty("WartoscBruttoPoRabacie", 1000);but something went wrong:
QAxBase::dynamicCallHelper: Pozycje: No such property in [unknown]
Candidates are:Set oSubDok = oSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA)QAxObject* oSubDok = oSubGT->querySubObject("Dokumenty"); oSubDok->dynamicCall("Dodaj(int)",0xFFFFFFF7); //gtaSubiektDokumentPA=0xFFFFFFF7 QAxObject* oSubPoz = oSubDok->querySubObject("Pozycje"); oSubPoz->dynamicCall("Dodaj(int)", 24);The C++ code does not do the same as the VBA code. Please look at it carefully.
In the VBA
oSubDokis set to the result ofoSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA). But in the C++oSubDokis only to set tooSubGT.Dokumenty. You callDodaj()on that but you do not use that as the resulting object to then calloSubDok->querySubObject("Pozycje")on. HencequerySubObject("Pozycje")is not found inoSubDokbecause that isoSubGT.Dokumentyrather thanoSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA).Please follow the VBA code more accurately when translating to C++.
-
I followed your advice and change below VBA :
Set oSubDok = oSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA) Set oSubPoz = oSubDok.Pozycje.Dodaj(23) oSubPoz.IloscJm = 13 oSubPoz.WartoscBruttoPoRabacie = 1000 oSubDok.Wyswietl oSubDok.Zamknijto C++ code :
QAxObject* oSubDok = oSubGT->querySubObject("Dokumenty"); QAxObject* oSubDokDod = oSubDok->querySubObject("Dodaj(int)",0xFFFFFFF7); QAxObject* oSubPoz = oSubDokDod->querySubObject("Pozycje"); QAxObject* oSubPozDod = oSubPoz->querySubObject("Dodaj(int)", 23); oSubPozDod->setProperty("IloscJm", 13); oSubPozDod->setProperty("WartoscBruttoPoRabacie", 1000); oSubDokDod->dynamicCall("Wyswietl"); oSubDokDod->dynamicCall("Zamknij");But stil is some wrong:
QAxBase: Error calling IDispatch member Wyswietl: Member not found
QAxBase: Error calling IDispatch member Zamknij: Member not found -
I followed your advice and change below VBA :
Set oSubDok = oSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA) Set oSubPoz = oSubDok.Pozycje.Dodaj(23) oSubPoz.IloscJm = 13 oSubPoz.WartoscBruttoPoRabacie = 1000 oSubDok.Wyswietl oSubDok.Zamknijto C++ code :
QAxObject* oSubDok = oSubGT->querySubObject("Dokumenty"); QAxObject* oSubDokDod = oSubDok->querySubObject("Dodaj(int)",0xFFFFFFF7); QAxObject* oSubPoz = oSubDokDod->querySubObject("Pozycje"); QAxObject* oSubPozDod = oSubPoz->querySubObject("Dodaj(int)", 23); oSubPozDod->setProperty("IloscJm", 13); oSubPozDod->setProperty("WartoscBruttoPoRabacie", 1000); oSubDokDod->dynamicCall("Wyswietl"); oSubDokDod->dynamicCall("Zamknij");But stil is some wrong:
QAxBase: Error calling IDispatch member Wyswietl: Member not found
QAxBase: Error calling IDispatch member Zamknij: Member not found@Damian7546
The last two items are (apparently) properties, like those set with yoursetProperty()calls, so tryoSubDokDod->property("Wyswietl")? Or maybe they don't exist, I don't know.You are making the translation from VBA to C++ harder/unclear by your choice of variable name in the C++ not corresponding exactly to the VBA.
Set oSubDok = oSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA)QAxObject* oSubDok = oSubGT->querySubObject("Dokumenty"); QAxObject* oSubDokDod = oSubDok->querySubObject("Dodaj(int)",0xFFFFFFF7);Make your C++
oSubDokrefer to exactly the same object as the VBAoSubDok. Don't name itoSubDokDod, that's unhelpful, instead use some other name for the intermediateQAxObject* oSubDok = oSubGT->querySubObject("Dokumenty");variable which does not exist in the VBA. -
@Damian7546
The last two items are (apparently) properties, like those set with yoursetProperty()calls, so tryoSubDokDod->property("Wyswietl")? Or maybe they don't exist, I don't know.You are making the translation from VBA to C++ harder/unclear by your choice of variable name in the C++ not corresponding exactly to the VBA.
Set oSubDok = oSubGT.Dokumenty.Dodaj(gtaSubiektDokumentPA)QAxObject* oSubDok = oSubGT->querySubObject("Dokumenty"); QAxObject* oSubDokDod = oSubDok->querySubObject("Dodaj(int)",0xFFFFFFF7);Make your C++
oSubDokrefer to exactly the same object as the VBAoSubDok. Don't name itoSubDokDod, that's unhelpful, instead use some other name for the intermediateQAxObject* oSubDok = oSubGT->querySubObject("Dokumenty");variable which does not exist in the VBA.@JonB said in QAxObject - transfer code from vba to qt:
You are making the translation from VBA to C++ harder/unclear by your choice of variable name in the C++ not corresponding exactly to the VBA.
you are right.
-
@JonB in your opinion how I should change below code:
Function UruchomSubiekta() As InsERT.Subiekt ... End Function Sub FS() Dim oSubGT As InsERT.Subiekt Set oSubGT = UruchomSubiekta() End Sub -
@JonB in your opinion how I should change below code:
Function UruchomSubiekta() As InsERT.Subiekt ... End Function Sub FS() Dim oSubGT As InsERT.Subiekt Set oSubGT = UruchomSubiekta() End Sub@Damian7546
Now you are going beyond my knowledge. I don't even use Windows, I just know how to do COM/Automation/VBA stuff from many years ago.You seem to be defining your own
Functions &Subs in VBA. I don't know how or whether you can do that from C++. It may not be possible, it may be a "feature" of VB/VBA to add user defined functions/procedures. I don't know if you can "extend" ActiveX objects from C++. You could presumably manage by putting in all the C++ code without defining it as ActiveX functions, or factor it into functions you can call in C++ without it actually "extending" the ActiveX object in any way.At the end of the day these are not really questions about Qt. You know what you have available from
QAxObjectin Qt, that is all you have.