Results 1 to 2 of 2

Thread: How to use a script for a value property with QtQuick1 ?

  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt/Embedded

    Default Re: How to use a script for a value property with QtQuick1 ?

    Hi,

    What is the best approach to work around the QtQuick1 limitations for this ?

    ListElement: cannot use script for property value
    remainingTimeElementRole: (function () { return (countDownTimerValue / 60 / 10).toFixed(0); }) ();

    I began without a closure, and then I had that idea to try out, but apparently no go.

    Here is the ListModel code:
    javascript Code:
    1. ListModel {
    2. id: remainingTimeModel;
    3. ListElement {
    4. remainingTimeElementRole: (countDownTimerValue / 60 / 10).toFixed(0);
    5. }
    6.  
    7. ListElement {
    8. remainingTimeElementRole: countDownTimerValue / 60 % 10;
    9. }
    10.  
    11. ListElement {
    12. remainingTimeElementRole: ":";
    13. }
    14.  
    15. ListElement {
    16. remainingTimeElementRole: (countDownTimerValue % 60 / 10).toFixed(0);
    17. }
    18.  
    19. ListElement {
    20. remainingTimeElementRole: countTimerDownTimerValue % 60 % 10;
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance!


    Added after 11 minutes:


    Probably for loop in a Component.onCompleted block inside the ListModel, and call ListModel append() with the appropriate values is the simplest hack around. :/
    Last edited by wysota; 8th February 2012 at 02:13. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use a script for a value property with QtQuick1 ?

    Define the function not as a lambda function but as a regular one and call it normally.

    javascript Code:
    1. ListModel {
    2.  
    3. function remainingTime(val) { return (val / 60 / 10).toFixed(0); }
    4.  
    5. ListElement { remainingTimeElementRole: remainingTime(val); }
    6. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 22nd April 2011, 10:20
  2. qt script property
    By wookoon in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2010, 10:41
  3. Using QT Script...
    By minhaz in forum Newbie
    Replies: 1
    Last Post: 18th August 2009, 22:29
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 03:01
  5. Qt script
    By rajesh_clt3 in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 12:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.