QT调用COM组件方式示例: https://blog.csdn.net/xiaolong1126626497/article/details/113127300?spm=1001.2014.3001.5501
VS2017 QT创建COM组件示例: https://blog.csdn.net/xiaolong1126626497/article/details/112556866
QT创建的COM组件里,类里提供的公共槽函数可以直接被其他语言调用,提供信号可以被其他语言绑定为事件,数据通信非常方便。
比如: QT如果调用已经注册的COM组件,可以绑定COM组件提供的信号到自己的指定的槽函数。
C#如果调用已经注册的COM组件,可以绑定COM组件提供的信号(事件) (QT生成的COM组件,信号传递出来的参数,在C#里接收回调函数里,从事件e结构里.号可以直接取出数据)。
代码语言:javascript复制class ComPluginTest : public QWidget, public QAxBindable
{
Q_OBJECT
public:
ComPluginTest(QWidget *parent = Q_NULLPTR);
public slots: //槽函数声明标志
void pushButton_int_clicked(); //声明槽函数
void pushButton_double_clicked(); //声明槽函数
void pushButton_string_clicked();
void pushButton_string1_clicked();
void pushButton_string2_clicked();
void pushButton_string3_clicked();
QString VersionNumber();
signals:
void signal_value_str1(const QString& str); //信号声明
void signal_value_str2(QString str); //信号声明
void signal_value_str3(QString str); //信号声明
void signal_value_string(QString &str); //信号声明
void signal_value_int(int); //信号声明
void signal_value_double(double); //信号声明
private:
Ui::ComPluginTestClass ui;
};
ActiveQt框架将属性和公共插槽公开为ActiveX属性和方法,将信号公开为ActiveX事件,并在Qt数据类型和等效的COM数据类型之间进行转换。
Qt支持作为COM组件信号和槽函数参数的数据类型如下:
Qt data type | COM property |
---|---|
bool | VARIANT_BOOL |
QString | BSTR |
int | int |
uint | unsigned int |
double | double |
qlonglong | CY |
qulonglong | CY |
QColor | OLE_COLOR |
QDate | DATE |
QDateTime | DATE |
QTime | DATE |
QFont | IFontDisp* |
QPixmap | IPictureDisp* |
QVariant | VARIANT |
QVariantList (same as QList<QVariant>) | SAFEARRAY(VARIANT) |
QStringList | SAFEARRAY(BSTR) |
QByteArray | SAFEARRAY(BYTE) |
QRect | User defined type |
QSize | User defined type |
QPoint | User defined type |
The Qt data types that are supported for parameters in signals and slots are:
Qt data type | COM parameter |
---|---|
bool | [in] VARIANT_BOOL |
bool& | [in, out] VARIANT_BOOL* |
QString, const QString& | [in] BSTR |
QString& | [in, out] BSTR* |
QString& | [in, out] BSTR* |
int | [in] int |
int& | [in,out] int |
uint | [in] unsigned int |
uint& | [in, out] unsigned int* |
double | [in] double |
double& | [in, out] double* |
QColor, const QColor& | [in] OLE_COLOR |
QColor& | [in, out] OLE_COLOR* |
QDate, const QDate& | [in] DATE |
QDate& | [in, out] DATE* |
QDateTime, const QDateTime& | [in] DATE |
QDateTime& | [in, out] DATE* |
QFont, const QFont& | [in] IFontDisp* |
QFont& | [in, out] IFontDisp** |
QPixmap, const QPixmap& | [in] IPictureDisp* |
QPixmap& | [in, out] IPictureDisp** |
QList<QVariant>, const QList<QVariant>& | [in] SAFEARRAY(VARIANT) |
QList<QVariant>& | [in, out] SAFEARRAY(VARIANT)* |
QStringList, const QStringList& | [in] SAFEARRAY(BSTR) |
QStringList& | [in, out] SAFEARRAY(BSTR)* |
QByteArray, const QByteArray& | [in] SAFEARRAY(BYTE) |
QByteArray& | [in, out] SAFEARRAY(BYTE)* |
QObject* | [in] IDispatch* |
QRect& | [in, out] struct QRect (user defined) |
QSize& | [in, out] struct QSize (user defined) |
QPoint& | [in, out] struct QPoint (user defined) |