PDA

View Full Version : C# codes transfer to QT with QaxObject



DJW602
24th May 2016, 01:17
My C# code with ActiveX Webbrowser:

webBrowser1.Document.GetElementsByTagName("A")[5];

I tried to make a program with activeX Webbrowser. The webBrowser1 is the name of ACTIVEX control. And I succeeded in C# with VS 2015 IDE. And now I need to work it out in C++ with QT frame(version 5.6).

and this is my attempt code:


QAxObject* myEles = MyWebObj->querySubObject("Document");
QAxObject* myEle = myEles->querySubObject("GetElementsByTagName(const Qstring&)", "A");
It seems that it can get Document correctly,but fail whatever next subobject is---it can compile successfully,but get error when running. It is really weird as I get everything right with ActiveX Excel with the same method.

I wonder what is wrong here.It is appreciated if someone can do it with the very ActiveX webbrowser.
And I wonder how to write to pick the element from a group with QT; Just like the example: I need to pick the 5th element. How to write it with QT?

anda_skoa
24th May 2016, 09:08
I have no experience with either ActiveX or ActiveQt, but are you sure that "Qstring" is an ActiveX type and that the function returns a single object (sounds like it would return a list of sorts).

Also, if you need access to DOM elements, maybe use a browser engine that has a Qt interface?
Or run the queries on the HTML side and communicate the results to the application with QWebChannel?
Or write the query code in C# and communicate the results to the Qt application?

Cheers,
_

ChrisW67
24th May 2016, 11:35
GetElementsByTagName() is a method of the Document object, not a sub-object. In all likelihood you want something like this:


QAxObject* myDoc = MyWebObj->querySubObject("Document");
QVariant myEles = myDoc->dynamicCall("GetElementsByTagName(const QString&)", "A");

Note the captialisation of QString. I do not know how you would access the list that myEles represents

DJW602
2nd June 2016, 08:41
Thanks. Indeed, I wrote qstring in a wrong way. But still I stuck at how to get access to a certain element from a bulk of objects. =_=

DJW602
14th June 2016, 14:26
I have to say I still get stuck here. I tried many ways to solve it,but only failed.T_T I just can 't believe I got stuck for just a grammar problem. No wonder someone says that C++ is inefficient. ::>_<::