• # Qt QAxObject 操作 ActiveX com组件


    - 起因是自己需要写一个Qt操作office word文档的类,

      总结出了QAxObject相关方法的使用模板

    - 大家可以对支持ActiveX的程序查程序API文档后对号入座

    - 程序名可以使用ApplicationName.Application或者Uuid

            - 使用ApplicationName的话可以到QtCreator的designer中

              拖拽一个QAxObject到窗口, 再右键添加控件, 就可以看到支持的控件

            - 找不到想要的控件的, 可以自己到注册表查询Uuid

    ```c++

    1. #include
    2. void qax_activeX_example_code()
    3. {
    4. QAxObject* obj2 = new QAxObject();
    5. obj2->setControl("ApplicationName.Application|Uuid");
    6. /* 间接获得程序接口 */
    7. QAxObject* obj = new QAxObject("ApplicationName.Application|Uuid");
    8. /* 直接获得程序接口 */
    9. obj->dynamicCall("Function()");
    10. /* dynamicCall时prototype必须显式的使用()表示Function是方法 */
    11. int arg = 0, arg2 = 1;
    12. obj->dynamicCall("Function(Arg, Arg2)", arg, arg2);
    13. /* 带参的dynamicCall */
    14. obj->setProperty("Attribute", arg); /* 设置属性 */
    15. int num = obj->property("Attribute").toInt();
    16. /* 获取相应属性(int) */ (void)num;
    17. bool can = obj->property("Attribute2").toBool();
    18. /* 获取相应属性(bool) */ (void)can;
    19. QString qstr2 = obj->property("Attribute3").toString();
    20. char* ch_str2 = (char*)qstr2.toStdString().c_str();
    21. /* 获取相应属性(QString --> char*) */ (void)ch_str2;
    22. char* ch_str = (char*)obj->property("Attribute3").toString()
    23. .toStdString().c_str();
    24. /* 获取相应属性(char*) */ (void)ch_str;
    25. QAxObject* sub_obj = obj->querySubObject("Parent.Sub");
    26. /* 从obj获取子对象(无参) */ (void)sub_obj;
    27. QAxObject* sub_obj2 = obj->querySubObject("Parent.Sub(arg)", arg);
    28. /* 从obj获取子对象(有参) */ (void)sub_obj2;
    29. QAxObject* sub_obj2 = obj->querySubObject("Sub(arg)", arg);
    30. /* 从obj获取子对象(有参), 也有可能是这种形式
    31. * 以所调程序对象的方法prototype为准
    32. */ (void)sub_obj2;
    33. }

    ```

  • 相关阅读:
    在js中使用grpc(包括代理)后端使用Go
    数据结构与算法编程题11
    韦东山嵌入式linux系列-具体单板的 LED 驱动程序
    GMS地下水数值模拟及溶质(包含反应性溶质)运移模拟技术
    MongoDB——centOS7环境Mongodb权限管理(图解版)
    pycharm安装opencv-python报错
    seacms_CNVD-2020-22721_v10.1漏洞分析与复现
    C语言中关于#include的一些小知识
    Java 文件操作
    Linux系统
  • 原文地址:https://blog.csdn.net/wo871427008/article/details/128124034