How to use QMapIterator with typedef'd QMultiMap [solved]



  • I use always use typedef to setup any STL type funcitonality (including QMap, QVector, etc..)

    So for example, I have this:

    @typedef QMultiMap<float, int>DistanceSorter;

    // To use this, I now can do this:

    DistanceSorter s;
    s[1.0] = 0;
    s[50.0] = 1;
    s[25] = 2;
    @

    I have used this convention for many years. But I need to do a reverse iterator through my list and I can't figure out how to do this.

    I've tried this:

    @

    DistanceSorter pset;

    pset[2.0] = 0;
    pset[1] = 1;
    pset[.5] = 3;

    QMapIterator<DistanceSorter> it<pset>;
    it.toBack();
    while( it.hasPrevious() ) {
    it.previous();
    ParticleObj *p = m_particles[it.value()];
    p->generatePoly(m_pVtxStream+idx++);
    }@

    But QMapIterator doesn't like this syntax. How do I use QMapIterator in this situation?



  • This worked:
    @
    DistanceSorter pset;

    pset[2.0] = 0;
    pset[1] = 1;
    pset[.5] = 3;

    QMapIterator<float, int> it(pset);
    it.toBack();
    while( it.hasPrevious() ) {
    it.previous();
    ParticleObj *p = m_particles[it.value()];
    p->generatePoly(m_pVtxStream+idx++);
    }
    @

    I had two problems. One: I can't use my typdef argument in the <> portion of the syntax. And I put Brackets after the iterator (supposed to be it(pset) not it<pset>).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.