• # 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. }

    ```

  • 相关阅读:
    高级 Kubernetes 部署策略
    Spring Boot Event Bus用法
    自动控制原理-2 控制系统的数学模型
    Vim程序编辑器
    开源的价值观与文化的传递
    【CSS】问题:为什么我的z-index不起作用
    解码2022中国网安强星丨正向建、反向查,华为构建数字化时代的网络安全防线
    程序员过中秋的一百种方式
    双十一特辑-北汇在C站的两周年打卡纪念:)
    第二证券:“零容忍”执法 资本市场加大防假打假力度
  • 原文地址:https://blog.csdn.net/wo871427008/article/details/128124034