Qt Development Activex Notes (2): Qt calls Activex controls developed by Qt

If the article is an original article, please indicate the original source for reprinting.
The blog address of this article: https://blog.csdn.net/qq21497936/article/details/113789693

We will continue to bring more projects and technology sharing for a long time, please add QQ: 21497936, WeChat: yangsir198808 for inquiries

Red Fatty (Red Imitation)'s blog post: development technology collection (including Qt practical technology, Raspberry Pi, 3D, OpenCV, OpenGL, ffmpeg, OSG, single-chip microcomputer, software and hardware combination, etc.) is being continuously updated... (click on the portal)

Qt Development Column: Development Technology

Previous: " Qt Development Activex Notes (1): Environment Setup, Basic Development Process and Demo Demo "
Next: " Qt Development Activex Notes (3): C# Calls Activex Controls Developed by Qt "


Preface

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


Demo

  Insert picture description here


QAxWidget

Overview

  The QAxWidget class is a QWidget that wraps ActiveX controls.
  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. The properties, methods and events of ActiveX controls only use the data types supported by QAxBase and can be used as Qt properties, slots and signals. The base class QAxBase provides an API that can directly access ActiveX through the IUnknown pointer.
  QAxWidget is a QWidget, which can usually be used like this, for example, it can be organized in a widget hierarchy and layout, or act as an event filter. Supports standard widget attributes, such as enabled, but it relies on ActiveX controls to support environment attributes (such as palete or font). QAxWidget tries to provide the necessary hints.
  However, you cannot reimplement Qt-specific event handlers, such as mousePressEvent or keyPressEvent, and expect to call them reliably. Embedded controls completely cover QAxWidget and usually deal with the user interface itself. Use control-specific APIs (that is, listen to control signals), or use standard COM techniques such as window procedure subclassing.
  QAxWidget also inherits most of the functions related to ActiveX from QAxBase, especially dynamicCall() and querySubObject().
  Warning: QAxWidget can be subclassed, but the Q_OBJECT macro cannot be used in the subclass (the generated moc file will not be compiled), so no more signals, slots or attributes can be added. This limitation is caused by the meta-object information generated at runtime. To solve this problem, aggregate QAxWidget as a member of QObject subclass.


Qt calls Activex method

Step 1: Register the activex control

  Register before running, use the idc that comes with Qt to register.

idc -regserver activeHelloWorldDemo.dll

  Insert picture description here

Step 2: Confirm the clsid of the activeQt control

  Check it, open the registry and search to confirm clsid, as shown below:
  Insert picture description here

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

Step 3: Use QAxWidget to call

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

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();
}

Previous: " Qt Development Activex Notes (1): Environment Setup, Basic Development Process and Demo Demo "
Next: " Qt Development Activex Notes (3): C# Calls Activex Controls Developed by Qt "

Guess you like

Origin blog.csdn.net/qq21497936/article/details/113789693