QML import later module version only if available?
<p>I have some work-in-progress QML code that currently requires QtCharts 2.1 from Qt 5.6. However, we are currently running our code using Qt 5.5.1, which only has QtCharts 2.0.</p>

<p>Is it possible to check in QML what the latest available version of QtCharts on the system is, <em>then</em> perform the proper import, and handle any associated special-case logic appropriately? I'd like to finish implementing my feature and merge it to the integration branch <em>without</em> breaking the GUI functionality on machines that have 5.5.1. (I'm okay having <em>this new feature</em> be broken for now, but currently it appears that the entire QML engine fails to load when a QML file contains invalid imports.)</p>

<p>Out of sheer indomitable hope, I tried the following:</p>

<pre><code>try {
    import QtCharts 2.1
} catch {
    import QtCharts 2.0
}
</code></pre>

<p>... which of course did not work, as <code>try</code> is not part of the QML root-level syntax.</p>

<hr>

<p>A related-but-not-quite-duplicate question is <a href="https://stackoverflow.com/q/27440425/1858225">here</a>. The distinction is that the OP for that question is apparently satisfied with using a <code>Loader</code> to dynamically load a <em>single QML element</em>. I don't think this trick can be used in my case, though, because <code>QtCharts</code> 2.0 and 2.1 contain the same QML element types, and in any case I don't know how to import "the latest" QtCharts available (as far as I can tell, the <code>import</code> statement syntax <em>requires</em> a specific version number).</p>

<p><strong>EDIT:</strong> As per my answer below, the <code>Loader</code> workaround <em>does</em> apparently work. So I suppose this is a duplicate after all.</p>