[Kstars-devel] GSoC progress : QList index out of range

M.S. Adityan msadityan at gmail.com
Sun Jun 14 13:52:55 UTC 2015


Hi,

I have added another class called ConstArtComponent. This class contains a
QList of ConstellationsArt objects. This QList will hold all the data
required for a Constellation Image. Currently this QList will hold 88
members, corresponding to 88 western constellations. We can add more QLists
corresponding to different sky cultures at a later point of time. KStars
compiles perfectly, but I get this error when I run KStars.

ASSERT failure in QList<T>::operator[]: "index out of range", file
/usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h, line 487
Aborted (core dumped)

Here is the code for constartcomponent.h

#ifndef CONSTARTCOMPONENT_H
#define CONSTARTCOMPONENT_H

#include "constellationsart.h"

class ConstellationsArt;

class ConstArtComponent
{
public:
    ConstArtComponent();
    ~ConstArtComponent();

    //Outputs details of the QList
    void showList();

    QList<ConstellationsArt> c_list;
};

#endif // CONSTARTCOMPONENT_H

Here is the code for constartcomponent.cpp

#include "constartcomponent.h"
#include "kstars/auxiliary/ksfilereader.h"

ConstArtComponent::ConstArtComponent()
{
    int i = 0;

    // Find constellation art file and open it. If it doesn't exist, output
an error message.
    KSFileReader fileReader;
    if ( ! fileReader.open("constellationsart.txt" ) )
    {
        qDebug() << "No constellationsart.txt file found for sky culture";
        return;
    }

    while ( fileReader.hasMoreLines() ) {
        QString line;

        line = fileReader.readLine();
        if( line.isEmpty() )
            continue;
        QChar mode = line.at( 0 );
        //ignore lines beginning with "#":
        if( mode == '#' )
            continue;

        //reads the first column from constellationart.txt
        c_list[i].rank = line.mid(0,2).trimmed().toInt();

        //Read pixel coordinates and HD number of star 1
//This works because ConstArtComponent is a fried class of ConstellationsArt
        c_list[i].x1 = line.mid( 3, 3 ).trimmed().toInt();
        c_list[i].y1 = line.mid( 7, 3 ).trimmed().toInt();
        c_list[i].hd1 = line.mid( 11, 6 ).trimmed().toInt();

        //Read pixel coordinates and HD number of star 2
        c_list[i].x2 = line.mid( 18, 3 ).trimmed().toInt();
        c_list[i].y2 = line.mid( 22, 3 ).trimmed().toInt();
        c_list[i].hd2 = line.mid( 26, 6 ).trimmed().toInt();

        //Read pixel coordinates and HD number of star 3
        c_list[i].x3 = line.mid( 33, 3 ).trimmed().toInt();
        c_list[i].y3 = line.mid( 37, 3 ).trimmed().toInt();
        c_list[i].hd3 = line.mid( 41, 6 ).trimmed().toInt();

        //Read abbreviation and image file name
        c_list[i].abbrev = line.mid( 48, 3 );
        c_list[i].imageFileName  = line.mid( 52 ).trimmed();

        //Make a QImage object pointing to constellation image
        c_list[i].c_image = QImage(c_list[i].imageFileName,0);
        i++;

        }
}
ConstArtComponent::~ConstArtComponent()
{

}

void ConstArtComponent::showList()
{
    int i = 0;
    for(i = 0; i < c_list.size(); i++)
    {
        qDebug()<<c_list[i].getx1();
    }
}

This is what I am doing ConstArtComponent obj; obj.showList();

I am not able to figure out where i am accessing an index that is out of
range. Can anyone help me with this?

Regards
M.S.Adityan
Website: www.msadityan.com
https://www.linkedin.com/in/msadityan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kstars-devel/attachments/20150614/5abe3e16/attachment.html>


More information about the Kstars-devel mailing list