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

    Hi,

    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:

    <RCC>
        <qresource prefix="/">
            <file>main.qml</file>
            <file>MainForm.ui.qml</file>
            <file>script.js</file>
        </qresource>
    </RCC>
    

    thanks!!


Log in to reply
 

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