如何在 QML 中编写条件导入语句? [英] How to write conditional import statements in QML?

查看:20
本文介绍了如何在 QML 中编写条件导入语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像我们在 C++ 中有条件包含的预处理器指令一样.

Like we have preprocessor directives in C++ for conditional includes.

同样,QML中如何进行条件importing?

Similarly, how to do conditional importing in QML?

if x  
    import ABC 1.0  
else  
    import PQR 2.0  

推荐答案

根据您想要实现的目标,可能的解决方法是使用 Loader.但它不导入模块,它只允许动态选择您将使用的 QML 组件.

Depending on what you want to achieve, a possible workaround is to use a Loader. But it does not import a module, it just allows to choose dynamically which QML component you'll use.

Loader
{
    source: condition?"RedRectangle.qml":"BlueRectangle.qml"
}

这篇关于如何在 QML 中编写条件导入语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆