Function argument is not accessible

Hi, my Qt application keeps getting killed by SIGSEGV, it seems that my function's argument is inaccessible (according to Qt's debugger, and it makes sense because the code crashes on the first line that uses this argument).

Here's the code that crashes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
building process_file(QString filename)
{
    building me;
    QDomDocument xml;
    QuaZipFile file(filename,CONTENT_XML); // Crashes here
    if(!file.open(QIODevice::ReadOnly))
    {
       return me;
    }
    qDebug()<<"Successfully opened "<<filename<<"/"<<CONTENT_XML<<" for reading.";
    if(!xml.setContent(&file))
    {
        qWarning("Could not open file %s as XML document",qPrintable(filename));
        return me;
    }
    QOdsReader::OdsDocument doc(&xml);
    QOdsReader::table tab = doc.getTable("COMPILER");
    for(int t=ja;t<de;t++)
    {
        me.total[t]=tab.getCell(t,1).text().toDouble();
        qDebug()<<t<<":"<<me.total[t];
    }

    file.close();
    return me;
}//*/ 

The funny thing is, if I use the old function (much uglier), everything works, and the only code that changed is after the line that crashes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
building process_file(QString filename) 
{
    building me;
    QDomDocument xml;
    QuaZipFile file(filename,CONTENT_XML);
    if(!file.open(QIODevice::ReadOnly))
    {
       return me;
    }
    qDebug()<<"Successfully opened "<<filename<<"/"<<CONTENT_XML<<" for reading.";
    if(!xml.setContent(&file))
    {
        qWarning("Could not open file %s as XML document",qPrintable(filename));
    }
    QDomElement docElem = xml.documentElement();
    QDomElement body=docElem.elementsByTagName("office:body").item(0).toElement();
    if(body.isNull()) //If body is null, then office:body was never found.
    {
        qWarning("File %s is corrupted",qPrintable(filename));
        building null;
        return null;
    }
    QDomNodeList tablelist=body.elementsByTagName(TABLETAG);
    QDomNode table;
    //!Need rows 7 to 18r
    QDomNodeList rows= docElem.elementsByTagName(ROWTAG);
    QDomElement row[12];
    QList<QDomNodeList> columns[12];
    QDomElement column[12][10];
    QString text[12][10];
    cell_value cell[12][10];
    for(int i=ROW_JAN;i<=ROW_DEC;i++)
    {
        row[i-ROW_JAN]= rows.item(i).toElement();
        for(int c=COLUMN_A;c<=COLUMN_K;c++)
        {
            bool ok=true;
            //Attempt at supporting annotations
            if(row[i-ROW_JAN].elementsByTagName(CELLTAG).at(c).toElement().elementsByTagName(TEXTTAG).at(0).parentNode().toElement().tagName().contains(ANNOTATIONTAG))
                column[i-ROW_JAN][c-COLUMN_A]=row[i-ROW_JAN].elementsByTagName(CELLTAG).at(c).toElement().elementsByTagName(TEXTTAG).at(1).toElement();
            else
                column[i-ROW_JAN][c-COLUMN_A]=row[i-ROW_JAN].elementsByTagName(CELLTAG).at(c).toElement().elementsByTagName(TEXTTAG).at(0).toElement();

            text[i-ROW_JAN][c-COLUMN_A]=column[i-ROW_JAN][c-COLUMN_A].text().remove("$",Qt::CaseInsensitive).remove(",",Qt::CaseInsensitive);
            qDebug()<<i-ROW_JAN<<"-"<<c-COLUMN_A<<":"<<text[i-ROW_JAN][c-COLUMN_A];
            cell[i-ROW_JAN][c-COLUMN_A]=text[i-ROW_JAN][c-COLUMN_A].toDouble(&ok);
            me.total[i-ROW_JAN]+=cell[i-ROW_JAN][c-COLUMN_A];
            if(!ok)
                qDebug()<<"toDouble() not ok.";
        }
    }
    qDebug()<<"Month totals:";
    for(int t=ja;t<de;t++)
    {
        qDebug()<<t<<":"<<me.total[t];
    }

    file.close();
    return me;
}//*/ 

I tried clean,qmake,rebuild several times, doesn't work. Does anyone have an idea?

Update:
I put the line
qDebug()<<"Processing file "<<filename;
at the very start of the function, I get the output as expected (Processing file "/home/gabars/Documents/[...]"), gdb still says that filename is inaccessible. Then I tried
1
2
3
QTextStream tmp;
tmp>>filename;
QString fn=tmp.readAll();

Still no luck... filename is still inaccessible and fn is set to an empty string.

Another update:
Ok, I changed the function so it's argument is a reference to a QString, now it works... I would still appreciate if someone could shed some light on this. To me this behavior seems illogical.
Last edited on
Topic archived. No new replies allowed.