qt-interest@trolltech.com
[Top] [All Lists]

Re: [Qt-interest] assert error in qmap "item_exists()"

Subject: Re: [Qt-interest] assert error in qmap "item_exists()"
From: "Ulf-Alexander v. Ceumern-Lindenstjerna"
Date: Mon, 12 Apr 2010 17:15:47 +0200
You forgot one small detail:

>     while (i.hasNext()) {
          i.next(); // <---------- insert this line
>         if (i.value() == currentChannel) {...

Also:
Checking if the item exists is not required before inserting
This line will already do it for you:
>         stageToChannelMap[stage] = channel;

This should simplify your mapStageToChannel function:

> void PiezoJenaController::mapStageToChannel(PiezoStage stage, int
> channel)
> {
>     stageToChannelMap[stage] = channel;
> }

Cheers, Ulf

> -----Original Message-----
> From: qt-interest-bounces@xxxxxxxxxxxxx [mailto:qt-interest-
> bounces@xxxxxxxxxxxxx] On Behalf Of Matthias Pospiech
> Sent: Monday, April 12, 2010 4:58 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: [Qt-interest] assert error in qmap "item_exists()"
> 
> The assert error happens in qmap.h in this line:
> Q_DECLARE_ASSOCIATIVE_ITERATOR(Map)
> 
> The QMap I am using contains 3 values which I can insert with no
> problem
> or error.
> However if I try to access the value (last line) I get this assertion:
> 
>     QMapIterator<PiezoStage, int> i(stageToChannelMap);
>     while (i.hasNext()) {
>         if (i.value() == currentChannel) {...
> 
> 
> The map is filled using:
> 
>     piezoController->mapStageToChannel(PiezoJenaController::X, 0);
>     piezoController->mapStageToChannel(PiezoJenaController::Y, 1);
>     piezoController->mapStageToChannel(PiezoJenaController::Z, 2);
> 
> with:
> 
> void PiezoJenaController::mapStageToChannel(PiezoStage stage, int
> channel)
> {
>     if (stageToChannelMap.contains(stage)) {
>         stageToChannelMap[stage] = channel;
>     } else {
>         stageToChannelMap.insert(stage, channel);
>     }
> }
> 
> 
> What am I possibly doing wrong?
> Matthias
> _______________________________________________
> Qt-interest mailing list
> Qt-interest@xxxxxxxxxxxxx
> http://lists.trolltech.com/mailman/listinfo/qt-interest

_______________________________________________
Qt-interest mailing list
Qt-interest@xxxxxxxxxxxxx
http://lists.trolltech.com/mailman/listinfo/qt-interest

<Prev in Thread] Current Thread [Next in Thread>