Important: Please read the Qt Code of Conduct -

Problem with import Javascript

  • hi!

    i have a problem with javascript.
    i created a Qt Quick Controls Application, and than i have created a script.js with qctreator.
    this file was automatically created in Other files directory.

    on my main.qml i have added this line:

    import QtQuick 2.6
    import QtQuick.Controls 1.5
    import QtQuick.Dialogs 1.2
    import "script.js" as Script

    and this is the error:

    QQmlApplicationEngine failed to load component
    qrc:/main.qml:4 Script qrc:/script.js unavailable
    qrc:/script.js:-1 File not found
    The program has unexpectedly finished.

    where am I doing wrong ?

  • Lifetime Qt Champion


    Do you have a .qrc file in your project ? Does it include script.js ?

  • hi!

    ok, i added the file into the qml.qrc, and it works:

        <qresource prefix="/">


Log in to reply