Results 1 to 16 of 16

Thread: use of Rectangle javascript

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: use of Rectangle javascript

    And you are posting this why?

    To show that a list of strings is not a string in case anyone would think that?

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    ravandi (31st January 2016)

  3. #2
    Join Date
    Oct 2015
    Posts
    46
    Platforms
    Windows
    Thanks
    19

    Default Re: use of Rectangle javascript

    I did try. but , it didn't work.
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.LocalStorage 2.0
    3. import QtQuick.Controls 1.1
    4. Rectangle {
    5. id: page2
    6. property var word:[]
    7. width: 360
    8. height: 360
    9.  
    10. Column {
    11. id: row
    12. spacing: 5;
    13.  
    14. Component.onCompleted:{
    15. var db = LocalStorage.openDatabaseSync("ravandi", "1.0", "The Example QML SQL!", 1000000);
    16. db.transaction(
    17. function(tx) {
    18. tx.executeSql('CREATE TABLE IF NOT EXISTS jadval(id integer primary key autoincrement not null,`name` varchar(40),`last` varchar(40))');
    19. tx.executeSql("insert into jadval (name,last) values('reza','ravandi')");
    20. var rs = tx.executeSql('SELECT * FROM jadval');
    21. for(var i = 0; i < rs.rows.length; i++) {
    22. word.push(rs.rows.item(i).name);
    23. print(word)
    24. }
    25. }
    26. )
    27. }
    28.  
    29. Repeater {
    30. id: repeater
    31. model: word;
    32. delegate: Rectangle {
    33. width:100
    34. height:30
    35. border.color: "red"
    36. border.width: 1
    37. Text{
    38. id:matn
    39. anchors.centerIn: parent
    40. text: modelData
    41. }
    42. }
    43. }
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: use of Rectangle javascript

    One important thing about programming is to not change code randomly at many places at the same time.

    You could have just fixed your code from comment #7 by using the correct property as the model instead of a totally unrelated one.
    But instead you changed how you fill the property and rename the property and fix the use of the property as a model.

    With your process you can only end up with working code by pure luck, if one of the many changes you make fixes the problem and all other random changes do not break new things.

    Oh and "it didn't work" is not a good description since it doesn't say what happend or did not happen.

    So:
    - fill a variable with the strings
    - assign that to the property you intend to use as the Repeater's model
    - use that property as the model, not some random other property


    Cheers,
    _

  5. #4
    Join Date
    Oct 2015
    Posts
    46
    Platforms
    Windows
    Thanks
    19

    Default Re: use of Rectangle javascript

    The problem was solved:
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.LocalStorage 2.0
    3. import QtQuick.Controls 1.1
    4. Rectangle {
    5. id: page2
    6. property var word:new Array
    7. property var namee:new Array
    8.  
    9. width: 360
    10. height: 360
    11.  
    12. Column {
    13. id: row
    14. spacing: 5;
    15.  
    16. Component.onCompleted:{
    17. var db = LocalStorage.openDatabaseSync("ravandi", "1.0", "The Example QML SQL!", 1000000);
    18. db.transaction(
    19. function(tx) {
    20. tx.executeSql('CREATE TABLE IF NOT EXISTS jadval(id integer primary key autoincrement not null,`name` varchar(40),`last` varchar(40))');
    21. tx.executeSql("insert into jadval (name,last) values('mohammad reza','ravandi')");
    22. var rs = tx.executeSql('SELECT * FROM jadval');
    23. for(var i = 0; i < rs.rows.length; i++) {
    24. namee =rs.rows.item(i).name
    25. word.push(namee);
    26. print(word)
    27. }
    28.  
    29. repeater.model = word
    30. }
    31. )
    32.  
    33. }
    34.  
    35. Repeater {
    36. id: repeater
    37. model: word;
    38. delegate: Rectangle {
    39. width:100
    40. height:30
    41. border.color: "red"
    42. border.width: 1
    43. Text{
    44. id:matn
    45. anchors.centerIn: parent
    46. text: modelData
    47. }
    48. }
    49. }
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: use of Rectangle javascript

    And you are needlessly using namee, also needlessly initializing it as an array.

    But nice to see that randomly changing code will sometimes lead to a solution as well.
    It only took two weeks longer then necessary. Maybe something you should think about.

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    ravandi (21st February 2016)

  8. #6
    Join Date
    Oct 2015
    Posts
    46
    Platforms
    Windows
    Thanks
    19

    Default Re: use of Rectangle javascript

    I would like to show the values field Last also.
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.LocalStorage 2.0
    3. import QtQuick.Controls 1.1
    4. Rectangle {
    5. id: page2
    6. property var word:new Array
    7. property var namee:new Array
    8.  
    9. width: 360
    10. height: 480
    11.  
    12. Column {
    13. id: row
    14. spacing: 5;
    15.  
    16. Component.onCompleted:{
    17. var db = LocalStorage.openDatabaseSync("ravandi", "1.0", "The Example QML SQL!", 1000000);
    18. db.transaction(
    19. function(tx) {
    20. tx.executeSql('CREATE TABLE IF NOT EXISTS jadval(id integer primary key autoincrement not null,`name` varchar(40),`last` varchar(40))');
    21. //tx.executeSql("insert into jadval (name,last) values('mohammad reza','ravandi')");
    22. var rs = tx.executeSql('SELECT * FROM jadval');
    23. for(var i = 0; i < rs.rows.length; i++) {
    24. namee =rs.rows.item(i).name
    25. word.push(namee);
    26. // print(word)
    27. }
    28. repeater.model = word
    29. }
    30. )
    31.  
    32. }
    33.  
    34. Repeater {
    35. id: repeater
    36. model: word.count;
    37. delegate: Rectangle {
    38. width:200
    39. height:30
    40. border.color: "red"
    41. border.width: 1
    42. Text{
    43. id:matn
    44. anchors.centerIn: parent
    45. // text:show values field name
    46. }
    47. Text{
    48. id:matn2
    49. //text:show values field last
    50. }
    51. }
    52. }
    53. }
    54. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ravandi; 21st February 2016 at 06:55.

  9. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: use of Rectangle javascript

    For that I would recommend switching to a ListModel instead of the array.

    1) Create a ListModel with an id and use that id as the Repeater's model
    2) Add some ListElement entries to the model that have the two data fields. That allows you to test the delegate with some fixed data
    3) Remove those entries again and modify your data gathering loop to call append() on the model instead of pushing to the array.

    Cheers,
    _

  10. The following user says thank you to anda_skoa for this useful post:

    ravandi (22nd February 2016)

  11. #8
    Join Date
    Oct 2015
    Posts
    46
    Platforms
    Windows
    Thanks
    19

    Default Re: use of Rectangle javascript

    I already values append () in javascript the empty() was empty.
    But I do not know how empty it in qml?
    please guide me!

  12. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: use of Rectangle javascript

    Quote Originally Posted by ravandi View Post
    But I do not know how empty it in qml?
    "it" being the ListModel instance?
    ListModel has a clear() method, easily discoverable by looking at the documentation.

    Cheers,
    _

  13. The following user says thank you to anda_skoa for this useful post:

    ravandi (23rd February 2016)

Similar Threads

  1. Replies: 2
    Last Post: 25th December 2014, 16:15
  2. is JavaScript necessary for QML???
    By ramin.lich in forum Newbie
    Replies: 2
    Last Post: 23rd November 2014, 21:07
  3. How to get javascript var value in qt
    By ram4soft in forum Qt Programming
    Replies: 0
    Last Post: 12th April 2011, 16:55
  4. Help with QML, JavaScript and C++
    By chetu1984 in forum Qt Quick
    Replies: 5
    Last Post: 14th February 2011, 23:42
  5. Replies: 9
    Last Post: 29th November 2010, 13:12

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
  •  
Qt is a trademark of The Qt Company.