| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 2 | |
Dear all, I am just starting to learn Qt. I wrote a program which I intended to teach kid addition. The idea is simple. In order to show 1+3, there will be 1 mouse followed by 3 mice, so that the kid will know the concept. The program is running, however, it only run for several minutes before it strokes. I tried my best to figure out the bug but without success. I wish I can provide more details so that you guys can help, but at point I have no clue where the problem is. Because the program runs without any error message, then strokes. Here I attach my program (source code), if any of you can check it out. I really appreciate. I am using Mac OS X (Tiger 10.4.11) with Qt 4.3. I suspect that the problem comes from the class AdditionForm if any of you can take a look. Best regards, Dave.
Attachment:
Attachment:
LearningAddition.zip
Description: Zip archive
Message 2 in thread
Dave Sun wrote:
> Dear all,
>
> I am just starting to learn Qt. I wrote a program which I intended to
> teach kid addition. The idea is simple. In order to show
> 1+3, there will be 1 mouse followed by 3 mice, so that the kid will know
> the concept.
>
> The program is running, however, it only run for several minutes before
> it strokes. I tried my best to figure out the bug but without
> success. I wish I can provide more details so that you guys can help,
> but at point I have no clue where the problem is. Because the
> program runs without any error message, then strokes.
>
> Here I attach my program (source code), if any of you can check it out.
> I really appreciate.
>
> I am using Mac OS X (Tiger 10.4.11) with Qt 4.3.
>
> I suspect that the problem comes from the class AdditionForm if any of
> you can take a look.
You're adding new mice during every updateScene() call. I suspect all
you wanted to do there was update their positions, not add a whole bunch
of new ones.
--
[ signature omitted ]
Message 3 in thread
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#3333ff">
<font size="+1">If you add one cat you will be able to demonstrate
subtraction as well as reduce your CPU consumption.<br>
<br>
Sorry..... long day.<br>
<br>
Robert<br>
</font><br>
Paul Miller wrote:
<blockquote cite="mid:47F6947A.2060407@xxxxxxxxxx" type="cite">Dave Sun
wrote:
<br>
<blockquote type="cite">Dear all, <br>
I am just starting to learn Qt. I wrote a program which I intended to
teach kid addition. The idea is simple. In order to show 1+3, there
will be 1 mouse followed by 3 mice, so that the kid will know the
concept. <br>
The program is running, however, it only run for several minutes before
it strokes. I tried my best to figure out the bug but without success.
I wish I can provide more details so that you guys can help, but at
point I have no clue where the problem is. Because the program runs
without any error message, then strokes. <br>
Here I attach my program (source code), if any of you can check it out.
I really appreciate. <br>
I am using Mac OS X (Tiger 10.4.11) with Qt 4.3. <br>
I suspect that the problem comes from the class AdditionForm if any of
you can take a look. </blockquote>
<br>
You're adding new mice during every updateScene() call. I suspect all
you wanted to do there was update their positions, not add a whole
bunch of new ones.
<br>
<br>
</blockquote>
</body>
</html>
--
[ signature omitted ]
Message 4 in thread
Dear Paul,
thank you for your response.
the updateScene() will add mice there. It works like this: if I want to show
2 + 3, first I add 2 mice, then 1 second later, I add the other 3. That is
what updateScene() does.
Thank you. I am still struggling with the mystery bug.
Dave.
On Fri, Apr 4, 2008 at 3:50 PM, Paul Miller <paul@xxxxxxxxxx> wrote:
> Dave Sun wrote:
>
> > Dear all,
> > I am just starting to learn Qt. I wrote a program which I intended to
> > teach kid addition. The idea is simple. In order to show 1+3, there will be
> > 1 mouse followed by 3 mice, so that the kid will know the concept.
> > The program is running, however, it only run for several minutes before
> > it strokes. I tried my best to figure out the bug but without success. I
> > wish I can provide more details so that you guys can help, but at point I
> > have no clue where the problem is. Because the program runs without any
> > error message, then strokes.
> > Here I attach my program (source code), if any of you can check it out.
> > I really appreciate.
> > I am using Mac OS X (Tiger 10.4.11) with Qt 4.3.
> > I suspect that the problem comes from the class AdditionForm if any of
> > you can take a look.
> >
>
> You're adding new mice during every updateScene() call. I suspect all you
> wanted to do there was update their positions, not add a whole bunch of new
> ones.
>
> --
> Paul Miller | paul@xxxxxxxxxx | www.fxtech.com | Got Tivo?
>
>
Message 5 in thread
Hello Trolls,
I thought that this press-release would be of interest to Qt users.
http://eeepc.asus.com/global/news03262008.htm
Regards,
Christopher
_________________________________________________________________
Enter today for your chance to win $1000 a day—today until May 12th. Learn more at SignInAndWIN.ca
http://g.msn.ca/ca55/215
Message 6 in thread
On Friday 04 April 2008, Dave Sun wrote:
> Dear all,
> I am just starting to learn Qt. I wrote a program which I intended to teach
> kid addition. The idea is simple. In order to show
> 1+3, there will be 1 mouse followed by 3 mice, so that the kid will know
> the concept.
>
> The program is running, however, it only run for several minutes before it
> strokes. I tried my best to figure out the bug but without
> success. I wish I can provide more details so that you guys can help, but
> at point I have no clue where the problem is. Because the
> program runs without any error message, then strokes.
Hint: use a debugger (e.g. gdb) to find out at which part of your code your
infinite loop is.
Then use qDebug()/printf()/cout/whatever to find the reason for it.
Your problem is in AdditionForm::newCard().
"rand" can take values 0,1,2,3,4 only. If AddNum1+AddNum2 (i.e. the correct
result) is among these values, then wrongList.size() can exceed 4 only if the
correct result is added to wrongList as well.
This can happen only if rand==AddNum1+AddNum2 in the very first iteration, as
you do not add it to wrongList in all other iterations (because you do a
flag+=1 then).
CU
Andi
--
[ signature omitted ]
Message 7 in thread
On Friday 04 April 2008 23:26:07 Andreas Beckermann wrote:
> Hint: use a debugger (e.g. gdb) to find out at which part of your code your
> infinite loop is.
if you're using gcc , stacktrace is very helpfull in finding recursion bugs.
svn://libqxt.org/svn/tools/stacktrace/profiler.cpp
--
[ signature omitted ]
Message 8 in thread
Just like Andreas has pinpoint the problem,
the easiest solution is to expand the range of:
int rand = qrand()%5;
into :
int rand = qrand()%19;
I use 19 because, addNum1 + addNum2 is in the range of 0 to 18.
By using this, the probability that (rand == addNum1+addNum2) will
decrease, and it would be less possible for infinite loop to occur.
Besides, I think the children would have more near correct answer
options in the choice buttons. So it will get them to think a bit
harder.
I modified part of your code into this, and I think this is more simple:
QList<int> wrongList;
while(wrongList.size()<=4)
{
int flag = 0;
int rand = qrand()%19;
if (wrongList.contains(rand)||rand==addNum1+addNum2)
flag += 1;
if (flag == 0)
wrongList.append(rand);
}
Regards,
Jesse
--
[ signature omitted ]