Common import for all qml files



  • Hi All,

    I have been using QML for a while and with every update new components as well as existing component are upgraded.

    This leads to the import statements which appear on top of the header file requiring to be updated as well

    import QtQuick 2.3
    import QtQuick.Controls 1.4
    

    and for earlier version

    import QtQuick 2.0
    

    Is there a way to put them in a common file and import that file to all the qml files so it's easier to maintain?

    Kindly advice



  • There is no need to import the new version unless you use any new properties, signals, or methods introduced in the new version. The underlying implementation is almost always the same. Just the new API is revisioned so that it won't be visible unless you import the new version, to avoid any potential conflicts with your existing code.



  • @jpnurmi Thanks for the replies.

    I have a lot of qml files and each file has different imports. Is it possible to have them in one location and import that location in all the qml files?



  • I'm afraid that is not possible in a sensible way.



  • Yes, you can do it by using '.qrc' files.

    1. Add Qt resource file by right clicking on project explorer.
      ![alt text](0_1472133618096_createQrc.jpg image url)2.

    2.Add all your qml files under this qrc.

    1. import this qrc like this
      "import "qrc:/sampleqrc/""

    all the files under "sampleqrc" will be available where ever you import this.



  • @Praveen-kk Hi Praveen.

    Let me clear the question

    one file "A" has the following import
    import QtQuick 2.3
    import QtQuick.Controls 1.2

    next file "B" has the following import
    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Layouts 1.1
    import Watson.Controls 1.0

    I would like a single file "C" with
    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Layouts 1.1
    import Watson.Controls 1.0

    and import this file "C" in both files "A" and "B".

    Can this be done?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.