×

Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    105

    Javascript variable not global among multiple qml files?

    I have a javascript file (myfile.js) which declares :

    var testVar = 0;

    then I have a file main.qml:

    import "myfile.js" as myfileJs;

    page{
    id :...;
    main2{
    id:testmain2;
    }
    button{
    onClicked:{
    myfileJs.testVar = 10;
    console.debug(myfileJs.testVar); ///Gives 10 on console
    pagestack.push(testmain2);
    }
    }
    }

    and another file, "main2.qml":

    import "myfile.js" as myfileJs;

    page{
    id :...2;
    button{
    onClicked:{
    console.debug(myfileJs.testVar); ///Gives 0 on console
    }
    }
    }

    Needless to say that in qmldir I declare main2 qml file.
    Anyone experienced the same?

  2. #2
    Regular Contributor
    Join Date
    Mar 2012
    Posts
    144

    Re: Javascript variable not global among multiple qml files?

    try to add
    .pragma library
    to your js file at the beginning

Similar Threads

  1. Global variable in js file to use in more QML files
    By AlterX in forum [Archived] Qt Quick
    Replies: 0
    Last Post: 2011-07-24, 10:48
  2. Replies: 5
    Last Post: 2010-10-12, 03:42
  3. how to decalre a global Variable
    By ragu. in forum Symbian
    Replies: 3
    Last Post: 2010-08-05, 07:54
  4. console exe global variable?
    By ptclin_2007 in forum Symbian
    Replies: 3
    Last Post: 2009-09-28, 04:18
  5. Use global variable in s3rd
    By andrew_lin in forum Symbian
    Replies: 6
    Last Post: 2008-05-03, 11:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×