[Kstars-devel] Opening files with KSFileReader

M.S. Adityan msadityan at gmail.com
Mon Jun 1 08:20:04 UTC 2015


Hi Jasem and Akarsh,

I am trying to test whether the code I wrote opens the
constellationsart.txt file and reads contents from it. I am able to build
kstars succesfully, but whenever I run kstars from the terminal, I get this
qDebug() message saying that No constellationsart.txt file found for sky
culture.  Here is the class:

class ConstellationsArt
{
private:
    QString abbrev, imageFileName;
    int x1,y1,x2,y2,x3,y3,hd1,hd2,hd3;

    /*Draw the constellation art
    void draw( SkyPainter* skyp ) const; */

public:

    //Constructor
    explicit ConstellationsArt(int serial);

    //Destructor
    virtual ~ConstellationsArt();

    //@return the object's x1
    inline int getx1() const { return x1; }

    //@return the object's y1
    inline int gety1() const { return y1; }

    //@return the object's x2
    inline int getx2() const { return x2; }

    //@return the object's y2
    inline int gety2() const { return y2; }

    //@return the object's x3
    inline int getx3() const { return x3; }

    //@return the object's y3
    inline int gety3() const { return y3; }

    //@return the object's hd1
    inline int gethd1() const { return hd1; }

    //@return the object's hd2
    inline int gethd2() const { return hd2; }

    //@return the object's hd3
    inline int gethd3() const { return hd3; }

};

Here is the .cpp file.
ConstellationsArt::ConstellationsArt(int serial)
{

    // Find constellation art file and open it. If it doesn't exist, output
an error message.
    //QString artFileName = "constellationsart.txt";
    KSFileReader fileReader;
    if ( !
fileReader.open("~/Projects/kstars/kstars/data/skycultures/western/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;

        serial=line.mid(0,2).trimmed().toInt(); //reads the first column
from constellationart.txt

        // reads the serial number for each constellation, matches it, if
matched then reads the details
        if(mode==serial){
            //Read pixel coordinates and HD number of star 1
            x1 = line.mid( 3, 3 ).trimmed().toInt();
            y1 = line.mid( 7, 3 ).trimmed().toInt();
            hd1 = line.mid( 11, 6 ).trimmed().toInt();


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


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

            abbrev = line.mid( 48, 3 );
            imageFileName  = line.mid( 52 ).trimmed();
        }
    qDebug()<< "Serial number"<<serial<<"abbreviation"<<abbrev;
    //testing to see if the file opens and outputs the data
    }
}


I have tried giving it the absolute path of the file. I also tried putting
constellationsart.txt into the build directory. What happens is KStars
compiles, but the console tells me that the file constellationsart.txt
didnt open.

Secondly, I want to see the contents of Hendry-Draper.idx, just to be sure
that all the HD numbers listed in constellationsart.txt are listed there
too. How do I do that?

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/20150601/4295707a/attachment.html>


More information about the Kstars-devel mailing list