Results 1 to 11 of 11

Thread: How to perform calculator functions in qt qml?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post How to perform calculator functions in qt qml?

    Hi all,
    I am new to qml and i am trying an application based on calculator.

    I am trying to perform addition in qml but i was not able to do with it.

    From my coding the output is displayed with the first input i give....

    For example:for adding two numbers->i am entering "2" in the first input and clicked on "+" button and entering the second input as "6" and when clicked on "=" i am getting the final output as "2".....


    Here is my code:

    javascript Code:
    1. import QtQuick 1.0
    2. import com.nokia.symbian 1.0
    3.  
    4. Page {
    5. id: mainPage
    6.  
    7. property string i;
    8. property string a;
    9. property string b;
    10. property string c;
    11. Button {
    12. id: button13
    13. x: 76
    14. y: 447
    15. text: "0"
    16. onClicked: {
    17. i = text
    18. t.text = t.text + i
    19.  
    20. }
    21. }
    22.  
    23. Button {
    24. id: button15
    25. x: 76
    26. y: 375
    27. text: "1"
    28. onClicked: {
    29. i = text
    30. t.text = t.text + i
    31. }
    32. }
    33.  
    34. Button {
    35. id: button2
    36. x: 136
    37. y: 375
    38. text: "2"
    39. onClicked: {
    40. i = text
    41. t.text = t.text + i
    42. }
    43. }
    44.  
    45. Button {
    46. id: button3
    47. x: 203
    48. y: 375
    49. text: "3"
    50.  
    51. onClicked: {
    52.  
    53. i = text
    54. t.text = t.text + i
    55.  
    56. }
    57. }
    58.  
    59.  
    60.  
    61. Button {
    62. id: button5
    63. x: 76
    64. y: 299
    65. text: "4"
    66. onClicked: {
    67. i = text
    68. t.text = t.text + i
    69.  
    70. }
    71. }
    72.  
    73. Button {
    74. id: button6
    75. x: 136
    76. y: 299
    77. text: "5"
    78. onClicked: {
    79.  
    80. i = text
    81. t.text = t.text + i
    82.  
    83. }
    84. }
    85.  
    86. Button {
    87. id: button7
    88. x: 203
    89. y: 299
    90. text: "6"
    91. onClicked: {
    92.  
    93. i = text
    94. t.text = t.text + i
    95. }
    96. }
    97.  
    98.  
    99.  
    100. Button {
    101. id: button9
    102. x: 76
    103. y: 235
    104. text: "7"
    105. onClicked: {
    106. i = text
    107. t.text = t.text + i
    108.  
    109.  
    110. }
    111. }
    112.  
    113. Button {
    114. id: button10
    115. x: 136
    116. y: 235
    117. text: "8"
    118. onClicked: {
    119.  
    120. i = text
    121. t.text = t.text + i
    122.  
    123. }
    124. }
    125.  
    126. Button {
    127. id: button11
    128. x: 203
    129. y: 235
    130. text: "9"
    131. onClicked: {
    132. i = text
    133. t.text = t.text + i
    134. }
    135. }
    136.  
    137.  
    138. Button {
    139. id: button4
    140. x: 136
    141. y: 447
    142. text: "+"
    143. onClicked: {
    144.  
    145. a = t.text
    146. t.text = ""
    147.  
    148. b = t.text
    149.  
    150. c = a + b
    151. }
    152.  
    153.  
    154. }
    155. Button {
    156. id: button8
    157. x: 264
    158. y: 299
    159. text: "-"
    160.  
    161. onClicked: {
    162.  
    163. t.text = a
    164. a.toString()
    165.  
    166. t.text = b
    167. b.toString()
    168.  
    169. c = a - b;
    170.  
    171. }
    172.  
    173. Button {
    174. id: button16
    175. x: 0
    176. y: 76
    177. text: "*"
    178.  
    179. onClicked: {
    180.  
    181. t.text = a
    182. a.toString()
    183.  
    184. t.text = b
    185. b.toString()
    186.  
    187. c = a * b;
    188. }
    189. Button {
    190. id: button12
    191. x: -58
    192. y: 72
    193. text: "/"
    194.  
    195. onClicked: {
    196.  
    197. t.text = a
    198. a.toString()
    199.  
    200. t.text = b
    201. b.toString()
    202.  
    203. c = a / b;
    204. }
    205.  
    206.  
    207. }
    208.  
    209.  
    210.  
    211.  
    212. TextField {
    213. id: t
    214. x:-188
    215. y:-237
    216. width: 230
    217. height: 50
    218. text: ""
    219.  
    220. }
    221. }
    222. }
    223.  
    224. Button {
    225. id: button1
    226. x: 267
    227. y: 447
    228. width: 39
    229. height: 42
    230. text: "="
    231.  
    232. onClicked: {
    233.  
    234. t.text = c
    235.  
    236.  
    237. }
    238. }
    239.  
    240. Button {
    241. id: button14
    242. x: 264
    243. y: 235
    244. width: 42
    245. height: 42
    246. text: "C"
    247. onClicked: {
    248.  
    249. t.text = ""
    250.  
    251. }
    252. }
    253.  
    254.  
    255. }
    To copy to clipboard, switch view to plain text mode 


    I think i am wrong with a small mistake anyone help me with this so that i can finish my task.

    Regards,
    Harish
    Last edited by wysota; 26th January 2012 at 12:47. Reason: missing [code] tags

Similar Threads

  1. how to perform search in QTableWidget?
    By aurora in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2012, 04:25
  2. Perform an automatic click on a webpage
    By manuelito2459 in forum Newbie
    Replies: 0
    Last Post: 25th December 2011, 21:50
  3. Replies: 5
    Last Post: 27th May 2011, 02:51
  4. Perform a cyclic task in a QState
    By schall_l in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2010, 23:18
  5. Replies: 12
    Last Post: 22nd March 2010, 08:59

Tags for this Thread

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.