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

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

问题描述

就像我们在C ++中有预处理器指令一样,它可以用于条件包含.

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

类似地,如何在QML中进行条件import?

Similarly, how to do conditional importing in QML?

if x  
    import ABC 1.0  
else  
    import PQR 2.0  

推荐答案

根据您要实现的目标,可能的解决方法是使用加载程序.但是它不导入模块,而只是允许动态选择要使用的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天全站免登陆