Using ActiveX controls in QT

Source: Internet
Author: User

The Windows commercial version of QT provides the framework for ACTIVEQT, using this component we can use ActiveX controls in Qt, and also develop Qt-based ActiveX controls. The ACTIVEQT contains two components Qaxcontainer and qaxserver.

L Qaxcontainer allows us to use COM objects, and we can embed ActiveX controls in the QT program.

L Qaxserver can export the QT control we write as a COM object or an ActiveX control.

The first example is to demonstrate the use of ShockwaveFlash as an ActiveX control in Qt.

#include <QApplication>

#include <QtGui>

#include <QAxWidget>

int main (int argc, char *argv[])

{

Qapplication A (argc, argv);

Qaxwidget *flash = new Qaxwidget (0,0);

Flash->resize (500,80);

Flash->setcontrol (Qstring::fromutf8 ("{d27cdb6e-ae6d-11cf-96b8-444553540000}"));

Flash->dynamiccall ("Loadmovie (long,string)", 0, "c:/1.swf");

Flash->show ();

return A.exec ();

}

Qaxcontainer is not included in Qtcore, so you must also add Config+=qaxcontainer to the. Pro file to use Qaxcontainer.

Here's an explanation of the above code:

1. First we create a Qaxwidget object. The Qaxwidget object is used to encapsulate ShockwaveFlash this ActiveX control. Qaxcontainer is made up of three classes. These are: Qaxobject encapsulates COM objects, Qaxwidget encapsulates ActiveX controls, Qaxbase is the parent of Qaxobject and Qaxwidget, and it implements the core function of encapsulating com.

The relationships of these three classes are as follows:

2. Then set ShockwaveFlash by Setcontrol the Class_id,class ID of this ActiveX control can be obtained through some other programming tools (Vc/delphi/microsoft ActiveX controls P AD). This will call CoCreateInstance to create an instance of the ActiveX control. All of the properties, methods, and events of this ActiveX control are then converted to qaxwidget, signals, and slots with Qt.

You can get and set the properties of an ActiveX control by calling the property () method of Qaxwidget and the SetProperty method.

Now that you can invoke the method properties of an ActiveX control, you also need to have a conversion of the data types in COM and the data types used in QT. Here is the table for the data types in COM and the data types in QT:

3. Use the Dynamiccall method to invoke the ActiveX control's method.

1) dynamiccall () passes a maximum of eight qvariant type parameters, and the return type is also qvariant.

2) if we need to pass IDispatch * or IUnknown *, we can encapsulate these components into qaxobject and then convert the COM object to qvariant by calling the Asvariant () method. Also, if we return an object of idispatch* or iunknown*, we need to convert the object to Qaxobject through the Querysubobject method.

Qaxobject *session = Outlook.querysubobject ("session");
3) If you do not want to do this, Qaxwidget also provides us with a QueryInterface method.
IWebBrowser2 *webbrowser = 0;
Activex->queryinterface (Iid_iwebbrowser2, (void *) &webbrowser);
if (WebBrowser) {
Webbrowser->navigate2 (Pvarurl);
Webbrowser->release ();
}
4) The Dynamiccall method can also set the properties of a COM control:
Activex->dynamiccall ("Value", 5);
QString Text = Activex->dynamiccall ("text"). ToString ();

5) You need to provide a completed function signature when calling a method of a COM object through Dynamiccall.

Activex->dynamiccall ("Navigate (const qstring&)", "qt.nokia.com");

http://blog.csdn.net/tingsking18/article/details/5403038

Using ActiveX controls in QT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.