If the paper is original articles, reprint please indicate the original source This article blog: blog.csdn.net/qq21497936/…

Long-term continuous bring more projects and technology to share, consultation please add QQ:21497936, wechat: yangsir198808

Development technology set (including Qt practical technology, raspberry PI, 3D, OpenCV, OpenGL, FFMPEG, OSG, SCM, soft and hard combination, etc.) continue to update… (Click on the portal)

Qt Development Column: Development techniques

Qt Development Activex Notes (a) : Environment setup, basic development process and Demo next article: Stay tuned…


preface

Develop Activex controls for other applications to call, this chapter explains Qt calls Activex controls, not limited to Qt developed Activex controls.


Demo

  


QAxWidget

An overview of the

The QAxWidget class is a QWidget that wraps ActiveX controls. A QAxWidget can be instantiated as an empty object with the name of the ActiveX control it should wrap, or with an existing interface pointer to the ActiveX control. Properties, methods, and events of ActiveX controls use only QAxBase supported data types and can be used as Qt properties, slots, and signals. The base class QAxBase provides an API that allows direct access to ActiveX through IUnknown Pointers. A QAxWidget is a QWidget that can be used, for example, organized in a widget hierarchy and layout, or as an event filter. Standard widget properties, such as Enabled, are supported, but it relies on ActiveX controls to support environment properties, such as palete or FONT. QAxWidget tries to provide the necessary hints. However, you cannot re-implement Qt-specific event handlers, such as mousePressEvent or keyPressEvent, and expect them to be called reliably. Embedded controls completely override qaxWidgets and typically handle the user interface itself. Use control-specific apis (that is, listen for signals on controls), or use standard COM techniques such as Window procedure subclassing. QAxWidget also inherits most activeX-related functionality from QAxBase, particularly dynamicCall() and querySubObject(). Warning: You can subclass QAxWidget, but you cannot use the Q_OBJECT macro in your subclass (the generated MOC file will not compile), so you cannot add more signals, slots, or properties. This limitation is due to the meta-object information generated at run time. To solve this problem, aggregate the QAxWidget as a member of the QObject subclass.


Qt calls Activex methods

Step 1: Register the ActiveX control

Use Qt to register idc before running.

idc -regserver activeHelloWorldDemo.dll
Copy the code

  

Step 2: Confirm the CLSID of the activeQt control

Take a look, open the registry and search to confirm the CLSID, as shown below:

"2F12BFB8-137D-4DC2-9A93-634EFE5A6DFC"
Copy the code

Step 3: Call using the QAxWidget

QAxWidget *pAxWidget = new QAxWidget();
pAxWidget->resize(400, 320);
pAxWidget->setControl("2F12BFB8-137D-4DC2-9A93-634EFE5A6DFC");
pAxWidget->show();
Copy the code


The source code

#include <QApplication>
#include <QAxWidget>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QAxWidget *pAxWidget = new QAxWidget();
    pAxWidget->resize(400, 320);
    pAxWidget->setControl("2F12BFB8-137D-4DC2-9A93-634EFE5A6DFC");
    pAxWidget->show();

    return a.exec();
}
Copy the code


Qt Development Activex Notes (a) : Environment setup, basic development process and Demo next article: Stay tuned…