Results 1 to 6 of 6

Thread: problem with indexes

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question problem with indexes

    Hi to all!

    I've added following code chunk to my application:
    Qt Code:
    1. // group names fetching
    2. QSqlQuery query; // database query
    3. query.setForwardOnly(true); // sets forward seeking only
    4. query.exec("SELECT * FROM `eros`.`grupa`;");
    5. while(query.next())
    6. {
    7. qDebug() << query.value(iGroupFieldNAME); // debug
    8. // extract names from database
    9. m_MerchandizeGroupsNames.append(query.value(iGroupFieldNAME).toString());
    10. }
    11.  
    12. m_pMerchandizeSelectorButtonsLayout=new QHBoxLayout(); // creates new horiz. layout
    13. Q_CHECK_PTR(m_pMerchandizeSelectorButtonsLayout); // checks creation
    14. quint16 iIndex; // loop index
    15. for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); iIndex++);
    16. //for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); ++iIndex);
    17. {
    18. // creates new button
    19. //QString buttonText=m_MerchandizeGroupsNames.at(iIndex); // gets button text
    20. QPushButton* pTempButton=new QPushButton(m_MerchandizeGroupsNames.at(iIndex), this);
    21. Q_CHECK_PTR(pTempButton);
    22. // adds button to list
    23. m_MerchandizeSelectorButtons.append(pTempButton);
    24. m_cPalette=m_MerchandizeSelectorButtons.at(iIndex)->palette(); // gets current pallete of button
    25. m_cPalette.setColor(QPalette::Button, Qt::black); // sets up new palette componenet
    26. m_cPalette.setColor(QPalette::ButtonText, Qt::white); // sets up new palette componenet
    27. m_MerchandizeSelectorButtons.at(iIndex)->setPalette(m_cPalette); // sets new pallete
    28. // adds newly created button to layout
    29. m_pMerchandizeSelectorButtonsLayout->addWidget(m_MerchandizeSelectorButtons.at(iIndex));
    30. delete pTempButton; // deletes temp button
    31. }
    To copy to clipboard, switch view to plain text mode 
    and the application stopped working. I went in debug mode with Eclipse and I caught following messages:
    Qt Code:
    1. 261-gdb-set confirm off
    2. 261^done
    3. 262-gdb-set width 0
    4. (gdb)
    5. 262^done
    6. 263-gdb-set height 0
    7. (gdb)
    8. 263^done
    9. 264-interpreter-exec console echo
    10. (gdb)
    11. 264^done
    12. 265-gdb-show prompt
    13. (gdb)
    14. 265^done,value="(gdb) "
    15. 266
    16. (gdb)
    17. &"\n"
    18. 266^done
    19. 267-gdb-set stop-on-solib-events 0
    20. (gdb)
    21.  
    22. 267^done
    23. 268-gdb-set new-console off
    24. (gdb)
    25. 268^done
    26. (gdb)
    27. 269-environment-cd "C:\\Documents and Settings\\markofr\\workspace\\eROSystem"
    28. 269^done
    29. 270-gdb-set environment PROMPT $P$G
    30. (gdb)
    31. 270^done
    32. 271-gdb-set environment SESSIONNAME Console
    33. (gdb)
    34. 271^done
    35. 272-gdb-set environment ComSpec C:\WINDOWS\system32\cmd.exe
    36. (gdb)
    37. 272^done
    38. (gdb)
    39. 273-gdb-set environment OS Windows_NT
    40. 273^done
    41. (gdb)
    42. 274-gdb-set environment ALLUSERSPROFILE C:\Documents and Settings\All Users
    43. 274^done
    44. (gdb)
    45. 275-gdb-set environment HOMEPATH \Documents and Settings\markofr
    46. 275^done
    47. (gdb)
    48. 276-gdb-set environment APPDATA C:\Documents and Settings\markofr\Application Data
    49. 276^done
    50. (gdb)
    51. 277-gdb-set environment TEMP C:\DOCUME~1\markofr\LOCALS~1\Temp
    52. 277^done
    53. (gdb)
    54. 278-gdb-set environment PROCESSOR_ARCHITECTURE x86
    55. 278^done
    56. (gdb)
    57. 279-gdb-set environment QTDIR C:\Qt\4.3.2
    58. 279^done
    59. (gdb)
    60. 280-gdb-set environment USERNAME markofr
    61. 280^done
    62. (gdb)
    63. 281-gdb-set environment SystemDrive C:
    64. 281^done
    65. (gdb)
    66. 282-gdb-set environment PROCESSOR_REVISION 4802
    67. 282^done
    68. (gdb)
    69. 283-gdb-set environment COMPUTERNAME ABAKUS
    70. 283^done
    71. (gdb)
    72. 284-gdb-set environment PROCESSOR_IDENTIFIER x86 Family 15 Model 72 Stepping 2, AuthenticAMD
    73. 284^done
    74. (gdb)
    75. 285-gdb-set environment USERDOMAIN ABAKUS
    76. 285^done
    77. (gdb)
    78. 286-gdb-set environment USERPROFILE C:\Documents and Settings\markofr
    79. 286^done
    80. (gdb)
    81. 287-gdb-set environment windir C:\WINDOWS
    82. 287^done
    83. (gdb)
    84. 288-gdb-set environment CommonProgramFiles C:\Program Files\Common Files
    85. 288^done
    86. (gdb)
    87. 289-gdb-set environment LOGONSERVER \\ABAKUS
    88. 289^done
    89. (gdb)
    90. 290-gdb-set environment QTJAVA "C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip"
    91. 290^done
    92. (gdb)
    93. 291-gdb-set environment PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    94. 291^done
    95. (gdb)
    96. 292-gdb-set environment CLIENTNAME Console
    97. 292^done
    98. (gdb)
    99. 293-gdb-set environment SystemRoot C:\WINDOWS
    100. 293^done
    101. (gdb)
    102. 294-gdb-set environment CLASSPATH "C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip"
    103. 294^done
    104. (gdb)
    105. 295-gdb-set environment ProgramFiles C:\Program Files
    106. 295^done
    107. (gdb)
    108. 296-gdb-set environment HOMEDRIVE C:
    109. 296^done
    110. (gdb)
    111. 298-gdb-set environment PROCESSOR_LEVEL 15
    112. 298^done
    113. (gdb)
    114. 299-gdb-set environment NUMBER_OF_PROCESSORS 2
    115. 299^done
    116. (gdb)
    117. 300-gdb-set environment FP_NO_HOST_CHECK NO
    118. 300^done
    119. (gdb)
    120. 301-gdb-set environment TMP C:\DOCUME~1\markofr\LOCALS~1\Temp
    121. 301^done
    122. (gdb)
    123. 302-gdb-set environment QMAKESPEC win32-g++
    124. 302^done
    125. 304 info threads
    126. &"info threads\n"
    127. &"No registers.\n"
    128. 304^error,msg="No registers."
    129. (gdb)
    130. 305-data-list-register-names
    131. 305^done,register-names=["eax","ecx","edx","ebx","esp","ebp","esi","edi","eip","eflags","cs","ss","ds","es","fs","gs","st0","st1","st2","st3","st4","st5","st6","st7","fctrl","fstat","ftag","fiseg","fioff","foseg","fooff","fop","xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","mxcsr","mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7"]
    132. 306-break-insert COperationWIndow.cpp:118
    133. (gdb)
    134. 306^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00402ec4",func="COperationWIndow::COperationWIndow(QWidget*)",file="COperationWIndow.cpp",fullname="C:/Documents and Settings/markofr/workspace/eROSystem/COperationWIndow.cpp",line="118",times="0"}
    135. (gdb)
    136. 307-break-insert -t main
    137. 307^done,bkpt={number="2",type="breakpoint",disp="del",enabled="y",addr="0x0040d6a9",at="<main+9>",times="0"}
    138. (gdb)
    139. 308-exec-run
    140. 308^running
    141. (gdb)
    142. ~"Current language: auto; currently c++\n"
    143. Current language: auto; currently c++
    144. 308*stopped,thread-id="1",frame={addr="0x0040d6a9",func="main",args=[]}
    145. (gdb)
    146. 309 info proc
    147. &"info proc\n"
    148. &"Undefined info command: \"proc\". Try \"help info\".\n"
    149. 309^error,msg="Undefined info command: \"proc\". Try \"help info\"."
    150. (gdb)
    151. 310 info program
    152. &"info program\n"
    153. ~"\tUsing the running image of child thread 1728.0x284.\n"
    154. ~"Program stopped at 0x40d6a9.\n"
    155. ~"It stopped at a breakpoint that has since been deleted.\n"
    156. ~"Type \"info stack\" or \"info registers\" for more information.\n"
    157. 310^done
    158. (gdb)
    159. 311 info threads
    160. &"info threads\n"
    161. ~"* 1 thread 1728.0x284 0x0040d6a9 in main ()\n"
    162. 311^done
    163. (gdb)
    164. 312-stack-info-depth
    165. 312^done,depth="1"
    166. (gdb)
    167. 313-stack-list-frames 0 1
    168. 313^done,stack=[frame={level="0",addr="0x0040d6a9",func="main"}]
    169. (gdb)
    170. 314-data-list-changed-registers
    171. 314^done,changed-registers=["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40"]
    172. (gdb)
    173. 316-exec-continue
    174. 316^running
    175. (gdb)
    176. warning: Lowest section in C:\WINDOWS\system32\xpsp2res.dll is .rsrc at 20001000
    177. &"warning: Lowest section in C:\\WINDOWS\\system32\\xpsp2res.dll is .rsrc at 20001000\n"
    178. &"warning: QVariant(QString, \"Glavne Jedi\") \n"
    179. &"\n"
    180. &"warning: QVariant(QString, \"Pijaee\") \n"
    181. warning: QVariant(QString, "Glavne Jedi")
    182.  
    183. warning: QVariant(QString, "Pijaee")
    184.  
    185. warning: QVariant(QString, "Sladice")
    186.  
    187. warning: QVariant(QString, "Solate")
    188.  
    189. warning: QVariant(QString, "Topli napitki")
    190.  
    191. warning: QVariant(QString, "Priloge in dodatki")
    192.  
    193. warning: ASSERT failure in QList<T>::at: "index out of range", file ../../../../Qt/4.3.2/include/QtCore/../../src/corelib/tools/qlist.h, line 386
    194.  
    195. &"\n"
    196. &"warning: QVariant(QString, \"Sladice\") \n"
    197. &"\n"
    198. &"warning: QVariant(QString, \"Solate\") \n"
    199. &"\n"
    200. &"warning: QVariant(QString, \"Topli napitki\") \n"
    201. &"\n"
    202. &"warning: QVariant(QString, \"Priloge in dodatki\") \n"
    203. &"\n"
    204. &"warning: ASSERT failure in QList<T>::at: \"index out of range\", file ../../../../Qt/4.3.2/include/QtCore/../../src/corelib/tools/qlist.h, line 386\n"
    205. &"\n"
    206. 316*stopped,reason="exited",exit-code="01"
    207. (gdb)
    208. 317-data-evaluate-expression $_exitcode
    209. 317^done,value="1"
    210. (gdb)
    211. 318-gdb-exit
    212. 318^exit
    To copy to clipboard, switch view to plain text mode 
    From this gdb output I found out qsqlquery is working ok, because I see database table contens as a result of qDebug(). That means database connection holds and everything is ok. But what I cannot figure out, why the hell I get out of QList index somwhere in this code chunk. Can someone please help me? And I was forced to strip some text from gdb output otherwise thread is too long to post.
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: problem with indexes

    Qt Code:
    1. for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); iIndex++);
    2. {
    3. // gets executed once
    4. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); iIndex++)
    2. {
    3. // gets executed m_MerchandizeGroupsNames.size() times
    4. }
    To copy to clipboard, switch view to plain text mode 
    PS. What's the idea with creating a temporary button, adding it to lists and layouts, and then deleting it right away?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: problem with indexes

    lol, i do not know myself. I do not know what I was thinkhing. Let me correct this now.

    Ok, I've commented that deletion, I get same result.

    lol, now I've seen ";" after "for" loop. I did not sleep today because of this error.

    Let me check now.

    Whoa, it works!!! Thanks, jpn!! I love you man.

    Now something is bothering me. Is it possible that database "informs" my app somehow that record was added/changed/deleted?
    Last edited by MarkoSan; 10th December 2007 at 07:04.
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    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: problem with indexes

    If you are using PostgreSQL then since 4.4 you'll have that possibility.

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: problem with indexes

    I use mysql
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    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: problem with indexes

    Quote Originally Posted by MarkoSan View Post
    I use mysql
    AFAIK MySql is not capable of notifying clients of database changes.

Similar Threads

  1. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  2. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.