The development of COM components in QT is really scary, because it is not a simple call, but requires someone to package COM and then use methods and classes in COM on the basis of packaging. We get used to the convenience brought by the VC compiler. Through the VC compiler, we only need to directly import the component compiler to automatically export the tlh description file of COM, next, the user can easily call the interface and use the method.
The latest qt sdk can be directly downloaded. These sdks are directly based on the mingw compiler. Therefore, if you want to use the COM component in the VC method, it will not work (an error not supported by the compiler will be reported ), you must compile the source code of QT in VC to use it. If you need to use COM components under the mingw compiler, you need to understand the packaging class of COM components by QT. The QT version I use is 4.7, which uses the qaxobject and qaxwidget classes. Qaxobject is the packaging of COM components, and qaxwidget is the packaging of ActiveX controls. For a simple understanding of functional encapsulation, we generally use common COM components. If the UI is involved, ActiveX controls are generally used. With these two classes, you can start simply calling components.
Qaxobject and qaxwidget can create an empty COM Component Object (which can be understood as a com container) through the default constructor, and then put the components to be encapsulated into the empty object. The Code is as follows:
Qaxobject object (qobject) 0); // create an encapsulated container
Object. setcontrol (qstring: fromutf8 ("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX }"));
// Fill in the COM component to be encapsulated into the container
Or merge the above two steps into one step, as shown in the following code:
Qaxobjectobject ("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX }");
Of course, the qaxwidget code is similar to the above.
It solves the problem of importing COM components and encapsulation. The next most important thing is how to use interfaces and methods. If the above import process involves CLSID (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) corresponds to a coclass problem is much easier to do, you can directly call this coclass method. Of course, if you do not have the QT Method for COM components in your hands, it is still difficult to start. In fact, COM is a self-describing structure. any third-party software can automatically export such descriptive information. Qt can be automatically exported by using the following code:
Qstringdoc =
Object. generatedocumentation ();
Qfile OUTFILE ("C:/debuglog.html ");
OUTFILE. Open (qiodevice: writeonly | qiodevice: append); qtextstreamts (& OUTFILE );
TS <doc <Endl;
After export, you will find that it is a very good help problem in HTML format, and each method has a detailed description of the call. You can start calling it by yourself after referring to the help,
Qvariantlistparams0;
Params0 <qvariant (INT) (W. winid ()));
Params0 <qvariant (1 );
Params0 <qvariant ("License ");
Params0 <qvariant ("");
Object. dynamiccall ("showstatusdialog (INT, Int, qvariant,
Qvariant) ", params0 );
The above method can complete most of the work. If the method involves many interfaces, I suggest using VC and QT, Which is troublesome. If you have to use it, consider exporting the proxy class of the COM component. The tool that comes with QT is dumpcpp. You can find a shortcut to the DOS environment in the directory after QT is installed, and then run dumpcpp directly. Refer to the help of dumpcpp. The exported file is. H ,. the CPP file is added to the project. Unfortunately, these exported. H ,. CPP files may not be used directly, because many custom interface variables are ignored during the export process. For example, some variables are int64, but QT does not, if some variables are defined based on int64, it is very likely that an error is reported. You should manually specify the definition as the qlonglong type. Other errors are similar. You only need to change the errors to the QT type.