PDA

View Full Version : problem with indexes



MarkoSan
10th December 2007, 07:19
Hi to all!

I've added following code chunk to my application:
// group names fetching
QSqlQuery query; // database query
query.setForwardOnly(true); // sets forward seeking only
query.exec("SELECT * FROM `eros`.`grupa`;");
while(query.next())
{
qDebug() << query.value(iGroupFieldNAME); // debug
// extract names from database
m_MerchandizeGroupsNames.append(query.value(iGroup FieldNAME).toString());
}

m_pMerchandizeSelectorButtonsLayout=new QHBoxLayout(); // creates new horiz. layout
Q_CHECK_PTR(m_pMerchandizeSelectorButtonsLayout); // checks creation
quint16 iIndex; // loop index
for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); iIndex++);
//for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); ++iIndex);
{
// creates new button
//QString buttonText=m_MerchandizeGroupsNames.at(iIndex); // gets button text
QPushButton* pTempButton=new QPushButton(m_MerchandizeGroupsNames.at(iIndex), this);
Q_CHECK_PTR(pTempButton);
// adds button to list
m_MerchandizeSelectorButtons.append(pTempButton);
m_cPalette=m_MerchandizeSelectorButtons.at(iIndex)->palette(); // gets current pallete of button
m_cPalette.setColor(QPalette::Button, Qt::black); // sets up new palette componenet
m_cPalette.setColor(QPalette::ButtonText, Qt::white); // sets up new palette componenet
m_MerchandizeSelectorButtons.at(iIndex)->setPalette(m_cPalette); // sets new pallete
// adds newly created button to layout
m_pMerchandizeSelectorButtonsLayout->addWidget(m_MerchandizeSelectorButtons.at(iIndex)) ;
delete pTempButton; // deletes temp button
}and the application stopped working. I went in debug mode with Eclipse and I caught following messages:
261-gdb-set confirm off
261^done
262-gdb-set width 0
(gdb)
262^done
263-gdb-set height 0
(gdb)
263^done
264-interpreter-exec console echo
(gdb)
264^done
265-gdb-show prompt
(gdb)
265^done,value="(gdb) "
266
(gdb)
&"\n"
266^done
267-gdb-set stop-on-solib-events 0
(gdb)

267^done
268-gdb-set new-console off
(gdb)
268^done
(gdb)
269-environment-cd "C:\\Documents and Settings\\markofr\\workspace\\eROSystem"
269^done
270-gdb-set environment PROMPT $P$G
(gdb)
270^done
271-gdb-set environment SESSIONNAME Console
(gdb)
271^done
272-gdb-set environment ComSpec C:\WINDOWS\system32\cmd.exe
(gdb)
272^done
(gdb)
273-gdb-set environment OS Windows_NT
273^done
(gdb)
274-gdb-set environment ALLUSERSPROFILE C:\Documents and Settings\All Users
274^done
(gdb)
275-gdb-set environment HOMEPATH \Documents and Settings\markofr
275^done
(gdb)
276-gdb-set environment APPDATA C:\Documents and Settings\markofr\Application Data
276^done
(gdb)
277-gdb-set environment TEMP C:\DOCUME~1\markofr\LOCALS~1\Temp
277^done
(gdb)
278-gdb-set environment PROCESSOR_ARCHITECTURE x86
278^done
(gdb)
279-gdb-set environment QTDIR C:\Qt\4.3.2
279^done
(gdb)
280-gdb-set environment USERNAME markofr
280^done
(gdb)
281-gdb-set environment SystemDrive C:
281^done
(gdb)
282-gdb-set environment PROCESSOR_REVISION 4802
282^done
(gdb)
283-gdb-set environment COMPUTERNAME ABAKUS
283^done
(gdb)
284-gdb-set environment PROCESSOR_IDENTIFIER x86 Family 15 Model 72 Stepping 2, AuthenticAMD
284^done
(gdb)
285-gdb-set environment USERDOMAIN ABAKUS
285^done
(gdb)
286-gdb-set environment USERPROFILE C:\Documents and Settings\markofr
286^done
(gdb)
287-gdb-set environment windir C:\WINDOWS
287^done
(gdb)
288-gdb-set environment CommonProgramFiles C:\Program Files\Common Files
288^done
(gdb)
289-gdb-set environment LOGONSERVER \\ABAKUS
289^done
(gdb)
290-gdb-set environment QTJAVA "C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip"
290^done
(gdb)
291-gdb-set environment PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
291^done
(gdb)
292-gdb-set environment CLIENTNAME Console
292^done
(gdb)
293-gdb-set environment SystemRoot C:\WINDOWS
293^done
(gdb)
294-gdb-set environment CLASSPATH "C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip"
294^done
(gdb)
295-gdb-set environment ProgramFiles C:\Program Files
295^done
(gdb)
296-gdb-set environment HOMEDRIVE C:
296^done
(gdb)
298-gdb-set environment PROCESSOR_LEVEL 15
298^done
(gdb)
299-gdb-set environment NUMBER_OF_PROCESSORS 2
299^done
(gdb)
300-gdb-set environment FP_NO_HOST_CHECK NO
300^done
(gdb)
301-gdb-set environment TMP C:\DOCUME~1\markofr\LOCALS~1\Temp
301^done
(gdb)
302-gdb-set environment QMAKESPEC win32-g++
302^done
304 info threads
&"info threads\n"
&"No registers.\n"
304^error,msg="No registers."
(gdb)
305-data-list-register-names
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"]
306-break-insert COperationWIndow.cpp:118
(gdb)
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"}
(gdb)
307-break-insert -t main
307^done,bkpt={number="2",type="breakpoint",disp="del",enabled="y",addr="0x0040d6a9",at="<main+9>",times="0"}
(gdb)
308-exec-run
308^running
(gdb)
~"Current language: auto; currently c++\n"
Current language: auto; currently c++
308*stopped,thread-id="1",frame={addr="0x0040d6a9",func="main",args=[]}
(gdb)
309 info proc
&"info proc\n"
&"Undefined info command: \"proc\". Try \"help info\".\n"
309^error,msg="Undefined info command: \"proc\". Try \"help info\"."
(gdb)
310 info program
&"info program\n"
~"\tUsing the running image of child thread 1728.0x284.\n"
~"Program stopped at 0x40d6a9.\n"
~"It stopped at a breakpoint that has since been deleted.\n"
~"Type \"info stack\" or \"info registers\" for more information.\n"
310^done
(gdb)
311 info threads
&"info threads\n"
~"* 1 thread 1728.0x284 0x0040d6a9 in main ()\n"
311^done
(gdb)
312-stack-info-depth
312^done,depth="1"
(gdb)
313-stack-list-frames 0 1
313^done,stack=[frame={level="0",addr="0x0040d6a9",func="main"}]
(gdb)
314-data-list-changed-registers
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"]
(gdb)
316-exec-continue
316^running
(gdb)
warning: Lowest section in C:\WINDOWS\system32\xpsp2res.dll is .rsrc at 20001000
&"warning: Lowest section in C:\\WINDOWS\\system32\\xpsp2res.dll is .rsrc at 20001000\n"
&"warning: QVariant(QString, \"Glavne Jedi\") \n"
&"\n"
&"warning: QVariant(QString, \"Pijaee\") \n"
warning: QVariant(QString, "Glavne Jedi")

warning: QVariant(QString, "Pijaee")

warning: QVariant(QString, "Sladice")

warning: QVariant(QString, "Solate")

warning: QVariant(QString, "Topli napitki")

warning: QVariant(QString, "Priloge in dodatki")

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"
&"warning: QVariant(QString, \"Sladice\") \n"
&"\n"
&"warning: QVariant(QString, \"Solate\") \n"
&"\n"
&"warning: QVariant(QString, \"Topli napitki\") \n"
&"\n"
&"warning: QVariant(QString, \"Priloge in dodatki\") \n"
&"\n"
&"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"
&"\n"
316*stopped,reason="exited",exit-code="01"
(gdb)
317-data-evaluate-expression $_exitcode
317^done,value="1"
(gdb)
318-gdb-exit
318^exitFrom 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.:confused::o

jpn
10th December 2007, 07:54
for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); iIndex++);
{
// gets executed once
}



for(iIndex=0; iIndex<m_MerchandizeGroupsNames.size(); iIndex++)
{
// gets executed m_MerchandizeGroupsNames.size() times
}

PS. What's the idea with creating a temporary button, adding it to lists and layouts, and then deleting it right away?

MarkoSan
10th December 2007, 07:57
lol, i do not know myself. :D I do not know what I was thinkhing. Let me correct this now.

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

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

Let me check now.

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

Now something is bothering me. Is it possible that database "informs" my app somehow that record was added/changed/deleted?

wysota
10th December 2007, 11:30
If you are using PostgreSQL then since 4.4 you'll have that possibility.

MarkoSan
10th December 2007, 14:14
I use mysql

wysota
10th December 2007, 15:55
I use mysql

AFAIK MySql is not capable of notifying clients of database changes.