You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

QT Installer Framework:组件筛选及添加虚拟组件至安装的实现方法

根据密钥控制ComponentSelectionPage组件显示
  • 先在自定义密钥输入页完成密钥验证,把验证结果存到全局变量(比如VALID_KEY)里
  • 然后在OnComponentSelectionBefore事件脚本中,遍历所有组件,根据密钥对应的权限设置组件的可见性:
    // InstallScript示例代码
    function OnComponentSelectionBefore()
    begin
        if VALID_KEY = "FEATURE_A_KEY" then
            // 仅显示FeatureA的组件,隐藏其余组件
            ComponentSetData(MEDIA, "ComponentB", COMPONENT_OPTIONS, COMPONENT_OPTION_HIDDEN);
            ComponentSetData(MEDIA, "ComponentC", COMPONENT_OPTIONS, COMPONENT_OPTION_HIDDEN);
        elif VALID_KEY = "FEATURE_B_KEY" then
            ComponentSetData(MEDIA, "ComponentA", COMPONENT_OPTIONS, COMPONENT_OPTION_HIDDEN);
            ComponentSetData(MEDIA, "ComponentC", COMPONENT_OPTIONS, COMPONENT_OPTION_HIDDEN);
        endif;
    end;
    
  • 如果是按功能模块(Feature)控制,用FeatureSetData隐藏整个Feature会更高效,逻辑也更清晰
虚拟组件添加至安装流程
  • 虚拟组件默认不会被安装程序自动处理,但可以手动将其纳入安装流程:
    • 在安装阶段(比如OnInstalling事件),调用MsiRegisterComponent手动注册虚拟组件,或者直接往注册表卸载信息项写入组件数据(路径为HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\[产品GUID]\Components)
    • 虽然没有现成的addVirtualComponentToInstall方法,但可以自行编写逻辑模拟,结合已有的addVirtualComponentToUninstall确保卸载正常:
      // 示例:手动将虚拟组件加入安装记录
      function AddVirtualComponentToInstall(sCompId, sCompName)
      string sRegPath;
      begin
          sRegPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + PRODUCT_GUID + "\\Components";
          RegSetStringValue(HKEY_LOCAL_MACHINE, sRegPath, sCompId, sCompName);
          // 同时注册到卸载列表
          addVirtualComponentToUninstall(sCompId);
      end;
      
    • 操作后,虚拟组件会被记录到安装信息中,卸载时也能被正确清理

内容的提问来源于stack exchange,提问作者Sergej Leus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 01:49:58