PDA

View Full Version : Program not running exited with code 0



gayathrisekaran
8th November 2012, 04:59
while running my qt code

Running build steps for project qbank...
Configuration unchanged, skipping QMake step.
Starting: /usr/bin/make debug -w
make: Entering directory `/home/tts/Desktop/QbankEditorAllrequirement'
/usr/bin/make -f Makefile.Debug
make[1]: Entering directory `/home/tts/Desktop/QbankEditorAllrequirement'
make[1]: Nothing to be done for `first'.
make[1]: Leaving directory `/home/tts/Desktop/QbankEditorAllrequirement'
make: Leaving directory `/home/tts/Desktop/QbankEditorAllrequirement'
Exited with code 0.

i'm working in qt4.

Running build steps for project qbank...
Configuration unchanged, skipping QMake step.
Starting: /usr/bin/make debug -w
make: Entering directory `/home/tts/Desktop/QbankEditorAllrequirement'
/usr/bin/make -f Makefile.Debug
make[1]: Entering directory `/home/tts/Desktop/QbankEditorAllrequirement'
make[1]: Nothing to be done for `first'.
make[1]: Leaving directory `/home/tts/Desktop/QbankEditorAllrequirement'
make: Leaving directory `/home/tts/Desktop/QbankEditorAllrequirement'
Exited with code 0.

while commiting to db i get the exit status as,

ASSERT: "i >= 0" in file /usr/include/qt4/QtCore/qstring.h, line 875
The program has unexpectedly finished.
/home/tts/Desktop/QbankEditorAllrequirement/qbank exited with code 0

when i debug my code

"The inferior stopped because it received a signal from the Operating system
Signal name : SIGABRT
Signal meaning : SignalAborting"

when i click ok,
it shows the error in my commit.cpp file,
in while loop.
any1 knows wat the error might be.please help me

Santosh Reddy
8th November 2012, 05:09
There may be an error in commit.cpp, check the call stack

gayathrisekaran
8th November 2012, 05:20
But the same code finely runs in qt3. will you please explain what is call stack.
thanks for your reply

Added after 5 minutes:

But the same code finely runs in qt3. will you please explain what is call stack.
thanks for your reply

Santosh Reddy
8th November 2012, 07:33
Refer this 8394

gayathrisekaran
8th November 2012, 08:28
Sorry, may be my question is a silly thing, but i am a beginner in both qt and c++ so please tell me weather in my code also it seems the same or not

Actually my code is


case SHORT:
/*write the parsing stuff ..... for parsing the options member of the object to seperate the statement and
main phrase parts*/
Ques=((Short *)object)->stmt[0];
Question=parseQuestion(Ques); // function called for replacing tilde,cape symbol to angluar brackets
Questemp=Question;
((Short *)object)->stmt[0]=Questemp;
temp = "\"" + chapter + "\", \"" + board + "\", \"" + subject + "\", \"" + temp2.setNum(((baseFillChoose *)object)->pageNo)+ "\", \"" + ((Short *)object)->Queswav + "\",";
temp += " \"" + ((Short *)object)->stmt[0] + "\",\"" + ((Short *)object)->mgif[0] + "\",\"" + ((Short *)object)->mgif1[0] + "\", \"" + ((Short *)object)->ChooseType + "\", \"" +((Short *)object)->misc[0] + "\"";
text12="insert into ShortQues(Chapter,Board,Subject,PageNo,Queswav,Que stion,Q1Gif1,Q1Gif2,Shorttype,StaticGif1) values (" + temp + ");";
cout<<"text12\n"<<text12<<endl;
query = new QSqlQuery("insert into ShortQues(Chapter,Board,Subject,PageNo,Queswav,Que stion,Q1Gif1,Q1Gif2,Shorttype,StaticGif1) values (" + temp + ")");
temp = "";
index = 0;
query = new QSqlQuery("select MAX(QNo) as QNo from ShortQues");
if(!query->first())
{
exit(-2);
}
qNo = (query->value(0)).toInt();

for(i = 0;i<object->getNumOpt();i++)
{
index = 0;
while((((Short *)object)->options[i])[index]!='\0') //here it points
{
index = parseOption(index,((Short *)object)->options[i],stmt1,phrase);
cout<<"index : "<<index<<"\n"<<stmt1<<"\n"<<phrase<<endl;
QString text11;
stmt1temp=stmt1;
cout<<"stmt1temp\n"<<stmt1temp<<endl;
stmt1=stmt1temp;
cout<<"stmt1\n"<<stmt1<<endl;
phrasetemp=phrase;
cout<<"phrasetemp\n"<<phrasetemp<<endl;
phrase=phrasetemp;
cout<<"phrase\n"<<phrase<<endl;
if(index!=-1)
{

text11="insert into ShAnsPts(Statement1,Statement2,Option1,QNo,PointNo ,CorrectNo) values (\"" + stmt1 + "\", NULL,\"" + phrase + "\"," + temp2.setNum(qNo) + "," + temp2.setNum(((Short *)object)->ptno[i+1]) + ",1)";
cout<<"\n\ntext11"<<text11<<endl;

query = new QSqlQuery("insert into ShAnsPts(Statement1,Statement2,Option1,QNo,PointNo ,CorrectNo) values (\"" + stmt1 + "\", NULL,\"" + phrase + "\"," + temp2.setNum(qNo) + "," + temp2.setNum(((Short *)object)->ptno[i+1])+",1)");
}
else {
query = new QSqlQuery("select MAX(APNo) as APNo from ShAnsPts where QNo=" + temp2.setNum(qNo) +"&& PointNo=" + temp2.setNum(((Short *)object)->ptno[i+1]));

if(!query->first())
{
cout<<"There is no main phrase in this point ..... aborting\n";
exit(-2);
}
aPNo = (query->value(0)).toInt();
cout<<"This is apNo values"<<aPNo<<endl;
stmt1=parseQuestion(stmt1); // function called for replacing tilde,cape symbol to angluar brackets
stmt2temp=parseStepNo(stmt1,i,aPNo);
cout<<"\nThis is the apno value required"<<aPNo<<endl;
// stmt2temp=stmt1;
stmt2=stmt2temp;
cout<<"This is STatement2 value"<<stmt2<<endl;
// (((baseFillChoose *)object)->stepno[i+1])=stepval[i];
// cout<<"This is stepmark value"<<stepval[i]<<endl;
query = new QSqlQuery("update ShAnsPts set Statement2 = \"" + stmt2 + "\" where APNo=" + temp2.setNum(aPNo));
// query = new QSqlQuery("update ShAnsPts set StepMark = \"" + ((baseFillChoose *)object)->stepno[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set Q1Gif1 = \"" + ((Short *)object)->mgif[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set Q1Gif2 = \"" + ((Short *)object)->mgif1[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set StaticGif1 = \"" + ((Short *)object)->misc[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set voiceover = \"" + ((Short *)object)->voiceovers[i+1] + "\" where APNo=" + temp2.setNum(aPNo));

}
}
}

break;

After entering into the following code

int mainForm::parseOption(int ind,QString option, QString &stmt1, QString &phrase)
{
QTextStream cout(stdout, QIODevice::WriteOnly);
int j = 0;
int index = ind;
cout<<"311 : parseOption : "<<option<<endl;
cout<<"index&&\n"<<index<<endl;
while(option[index] != '|')
{
stmt1[j] = option[index];
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;
if(option[index]=='\0')
{
stmt1[j] = '\0';
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;
option[0] = '\0';
cout<<"option[0]\n"<<option[0]<<endl;
return -1;
}
index++;
j++;
}
stmt1[j] = '\0';
cout<<"stmt1[j]**&\n"<<stmt1[j]<<endl;
stmt1=stmt1.replace( "{sub}","<sub>");
stmt1=stmt1.replace( "{/sub}","</sub>" );

cout<<"425 : "<<stmt1<<endl;
j = 0;
index++;
while(option[index] != '\\')
{
phrase[j] = option[index];
index++;
j++;
}
phrase=phrase.replace( "{sub}","<sub>" );
phrase=phrase.replace( "{sub}","<sub>" );
cout<<"Phrase value"<<phrase<<endl;
phrase[j] = '\0';
cout<<"436 : "<<phrase<<endl;

return (index + 1);

}

then return to the above while condition

it exit and showing
ASSERT: "i >= 0" in file /usr/include/qt4/QtCore/qstring.h, line 875
The program has unexpectedly finished.
/home/tts/Desktop/QbankEditorAllrequirement/qbank exited with code 0

Santosh Reddy
8th November 2012, 09:04
int mainForm:arseOption(int ind,QString option, QString &stmt1, QString &phrase)
{
...
while(option[index] != '|') //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
stmt1[j] = option[index]; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;//<<<<<<<<<<<<<<<<<<<<<
if(option[index]=='\0')//<<<<<<<<<<<<<<<<<<<<<
{
stmt1[j] = '\0';
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;//<<<<<<<<<<<<<<<<<<<<<
option[0] = '\0';
cout<<"option[0]\n"<<option[0]<<endl;//<<<<<<<<<<<<<<<<<<<<<
return -1;
}
index++;
j++;
}
...
}
Refer the comments in code, you are using operator []. What do you think will happen if use stmt[i] or option[index] when stmt and option are empty strings?

gayathrisekaran
8th November 2012, 10:35
The '|' operator is used, when entering the options.
To highlight the important phrase in the answers '|' operator is used.

Added after 18 minutes:

Through editor, i am entering the question and answers.
After entering the question and answers,it then comes to "parse" functions.
Then how will it take the stmt and option as empty string.
Its just to check, if stmt and options are empty then it should print empty,otherwise it should have to execute the query.
Bt i've given both question and answers, then hw it seems to be empty.

Added after 1:

Through the editor i am entering the question in the database.But for entering shortquestions and Longquestions while "entering the questions" it enter into the "parseQuestion" function and enter the query into the database.
Also in "parseOption" function it is parsing the question itself and not the answers and none is updated in the database (i.e in queston table the question is entering. bt in answer table nothing get entered).
showing the table empty.
In that code, some conditions are checked for entering the options.
In the "parseOption" function the options is to be parsed. But for me the question itself is getting parsed.
Eventhough i enter the option in that format, and when i clicked commit to db i still get exit from my editor returning that status.

ASSERT: "i >= 0" in file /usr/include/qt4/QtCore/qstring.h, line 875
The program has unexpectedly finished.
/home/tts/Desktop/QbankEditorAllrequirement/qbank exited with code 0

will you please tell me why it is taking like tat.

gayathrisekaran
8th November 2012, 12:57
Sometimes it get entered to db and sometimes not.Will u please tell me wat the problem is?

Added after 28 minutes:

while entering the Ques it get parsed in the following code

QString mainForm::parseQuestion(QString &stmt1)
{
QTextStream cout(stdout, QIODevice::WriteOnly);
cout<<"It is coming inside the parse function"<<endl;
stmt1=stmt1.replace( QChar('^'),QChar('<') );
stmt1=stmt1.replace( QChar('~'),QChar('>') );
stmt1=stmt1.replace( "{sub}","<sub>" );
stmt1=stmt1.replace( "{/sub}","</sub>" );
stmt1=stmt1.replace( "{sup}","<sup>" );
stmt1=stmt1.replace( "{/sup}","</sup>" );
return(stmt1);
}

And when the options get entered it is nt parsing in the "parseOption" function.
The "parseOption" function also parses the Ques itself, and tat Ques is taken as the stmt value one by one and finally printing as the stmt as[].
The option isprinting as []. Y its taking lik tis pls tell me :(

Santosh Reddy
8th November 2012, 14:46
First use tags to post your code, nobody will be interested to look at your code if it is not readable quickly, (eg. [CODE]....[ /CODE])

gayathrisekaran
8th November 2012, 16:34
sorry



case SHORT:
/*write the parsing stuff ..... for parsing the options member of the object to seperate the statement and
main phrase parts*/
Ques=((Short *)object)->stmt[0];
Question=parseQuestion(Ques); // function called for replacing tilde,cape symbol to angluar brackets
Questemp=Question;
((Short *)object)->stmt[0]=Questemp;
temp = "\"" + chapter + "\", \"" + board + "\", \"" + subject + "\", \"" + temp2.setNum(((baseFillChoose *)object)->pageNo)+ "\", \"" + ((Short *)object)->Queswav + "\",";
temp += " \"" + ((Short *)object)->stmt[0] + "\",\"" + ((Short *)object)->mgif[0] + "\",\"" + ((Short *)object)->mgif1[0] + "\", \"" + ((Short *)object)->ChooseType + "\", \"" +((Short *)object)->misc[0] + "\"";
text12="insert into ShortQues(Chapter,Board,Subject,PageNo,Queswav,Que stion,Q1Gif1,Q1Gif2,Shorttype,StaticGif1) values (" + temp + ");";
cout<<"text12\n"<<text12<<endl;
query = new QSqlQuery("insert into ShortQues(Chapter,Board,Subject,PageNo,Queswav,Que stion,Q1Gif1,Q1Gif2,Shorttype,StaticGif1) values (" + temp + ")");
temp = "";
index = 0;
query = new QSqlQuery("select MAX(QNo) as QNo from ShortQues");
if(!query->first())
{
exit(-2);
}
qNo = (query->value(0)).toInt();

for(i = 0;i<object->getNumOpt();i++)
{
index = 0;
while((((Short *)object)->options[i])[index]!='\0') //here it points
{
index = parseOption(index,((Short *)object)->options[i],stmt1,phrase);
cout<<"index : "<<index<<"\n"<<stmt1<<"\n"<<phrase<<endl;
QString text11;
stmt1temp=stmt1;
stmt1=stmt1temp;
phrasetemp=phrase;
phrase=phrasetemp;
if(index!=-1)
{

text11="insert into ShAnsPts(Statement1,Statement2,Option1,QNo,PointNo ,CorrectNo) values (\"" + stmt1 + "\", NULL,\"" + phrase + "\"," + temp2.setNum(qNo) + "," + temp2.setNum(((Short *)object)->ptno[i+1]) + ",1)";
cout<<"\n\ntext11"<<text11<<endl;

query = new QSqlQuery("insert into ShAnsPts(Statement1,Statement2,Option1,QNo,PointNo ,CorrectNo) values (\"" + stmt1 + "\", NULL,\"" + phrase + "\"," + temp2.setNum(qNo) + "," + temp2.setNum(((Short *)object)->ptno[i+1])+",1)");
}
else {
query = new QSqlQuery("select MAX(APNo) as APNo from ShAnsPts where QNo=" + temp2.setNum(qNo) +"&& PointNo=" + temp2.setNum(((Short *)object)->ptno[i+1]));

if(!query->first())
{
cout<<"There is no main phrase in this point ..... aborting\n";
exit(-2);
}
aPNo = (query->value(0)).toInt();
cout<<"This is apNo values"<<aPNo<<endl;
stmt1=parseQuestion(stmt1); // function called for replacing tilde,cape symbol to angluar brackets
stmt2temp=parseStepNo(stmt1,i,aPNo);
cout<<"\nThis is the apno value required"<<aPNo<<endl;
// stmt2temp=stmt1;
stmt2=stmt2temp;
cout<<"This is STatement2 value"<<stmt2<<endl;
// (((baseFillChoose *)object)->stepno[i+1])=stepval[i];
// cout<<"This is stepmark value"<<stepval[i]<<endl;
query = new QSqlQuery("update ShAnsPts set Statement2 = \"" + stmt2 + "\" where APNo=" + temp2.setNum(aPNo));
// query = new QSqlQuery("update ShAnsPts set StepMark = \"" + ((baseFillChoose *)object)->stepno[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set Q1Gif1 = \"" + ((Short *)object)->mgif[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set Q1Gif2 = \"" + ((Short *)object)->mgif1[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set StaticGif1 = \"" + ((Short *)object)->misc[i+1] + "\" where APNo=" + temp2.setNum(aPNo));
query = new QSqlQuery("update ShAnsPts set voiceover = \"" + ((Short *)object)->voiceovers[i+1] + "\" where APNo=" + temp2.setNum(aPNo));

}
}
}

break;




int mainForm:arseOption(int ind,QString option, QString &stmt1, QString &phrase)
{
QTextStream cout(stdout, QIODevice::WriteOnly);
int j = 0;
int index = ind;
cout<<"311 : parseOption : "<<option<<endl;
cout<<"index&&\n"<<index<<endl;
while(option[index] != '|')
{
stmt1[j] = option[index];
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;
if(option[index]=='\0')
{
stmt1[j] = '\0';
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;
option[0] = '\0';
cout<<"option[0]\n"<<option[0]<<endl;
return -1;
}
index++;
j++;
}
stmt1[j] = '\0';
cout<<"stmt1[j]**&\n"<<stmt1[j]<<endl;
stmt1=stmt1.replace( "{sub}","<sub>");
stmt1=stmt1.replace( "{/sub}","</sub>" );

cout<<"425 : "<<stmt1<<endl;
j = 0;
index++;
while(option[index] != '\\')
{
phrase[j] = option[index];
index++;
j++;
}
phrase=phrase.replace( "{sub}","<sub>" );
phrase=phrase.replace( "{sub}","<sub>" );
cout<<"Phrase value"<<phrase<<endl;
phrase[j] = '\0';
cout<<"436 : "<<phrase<<endl;

return (index + 1);

}




QString mainForm:arseQuestion(QString &stmt1)
{
QTextStream cout(stdout, QIODevice::WriteOnly);
cout<<"It is coming inside the parse function"<<endl;
stmt1=stmt1.replace( QChar('^'),QChar('<') );
stmt1=stmt1.replace( QChar('~'),QChar('>') );
stmt1=stmt1.replace( "{sub}","<sub>" );
stmt1=stmt1.replace( "{/sub}","</sub>" );
stmt1=stmt1.replace( "{sup}","<sup>" );
stmt1=stmt1.replace( "{/sup}","</sup>" );
return(stmt1);
}

Santosh Reddy
8th November 2012, 18:09
What do you think will this statement will do "stmt1[j] = '\0';"

You are null terminating a QString with '\0', you don't have do it. All such assignments in your code will to crash your application one day or other.

Either user all char * (C strings), or user all QStrings (and use them the way they are supposed to be used).

I recommend to spend some time reading some Qt documentation and example, before writing such complicated statements for simple operations on at-least QString.

by the way there are lot of variable which I cannot even image the type.
what is type of object?
what is type of baseFillChoose?
what is type of temp2?
and so may things...

ChrisW67
8th November 2012, 21:15
ASSERT: "i >= 0" in file /usr/include/qt4/QtCore/qstring.h, line 875
The program has unexpectedly finished.
/home/tts/Desktop/QbankEditorAllrequirement/qbank exited with code 0


You don't say what version of Qt you are using. In my Qt 4.8.2 source the only place in qstring.h with that Q_ASSERT statement implies that your code is attempting to retrieve a character from a string using a negative index. That is, somewhere you use code like:


x = string[i];
// or
x = string.at(i);

the value of 'i' is negative. This is exactly the sort of thing Santosh has been asking you to consider.


But the same code finely runs in qt3.
The code will run without stopping if you compile a release version because the index idiot checks are not done. This is not the same thing as "finely runs". The program will still be broken in unpredictable ways.


will you please explain what is call stack.

When you run the program in your debugger it will stop the first time you try to access the string with a negative index. The Qt Creator panel that Santosh identified contains what is called a "backtrace", "stack trace", or "call stack". The first line is the last bit of code to execute, the line after that is where that block of code was called form, the line after that is where that block of code was called from etc... Read down the list until the first line that is in one of your source files. That is where your problem started. In Qt Creator you can double-click on that line and the "Locals and expressions" will display all the variables in scope at that time... find the problem here.

If you are not using Qt Creator you need to find the equivalent of the backtrace and variable inspection facilities in you IDE... they all have them.

Aside from that your constant, unsafe, C-style casting of the variable "object" to different types is just asking for trouble.

gayathrisekaran
9th November 2012, 06:08
I am using Qt4.6.2.
While debugging, i am getting like this




The inferior stopped because it received a signal from the Operating system


Signal name : SIGABRT
Signal meaning : Aborted



The following is the exact piece of code where it points, When clicking ok.


inline QCharRef QString::operator[](int i)
{ Q_ASSERT(i >= 0); return QCharRef(*this, i); } // here it points


filename is qstring.h
Is there anything wrong in that.

The exact problem i am having is,
I've to enter the short question and short answers in seperate table in database through the editor.
By entering the question and answers,
it have to parse the question in "parseQuestion" function.



QString mainForm::parseQuestion(QString &stmt1)
{
QTextStream cout(stdout, QIODevice::WriteOnly);
cout<<"It is coming inside the parse function"<<endl;
stmt1=stmt1.replace( QChar('^'),QChar('<') );
stmt1=stmt1.replace( QChar('~'),QChar('>') );
stmt1=stmt1.replace( "{sub}","<sub>" );
stmt1=stmt1.replace( "{/sub}","</sub>" );
stmt1=stmt1.replace( "{sup}","<sup>" );
stmt1=stmt1.replace( "{/sup}","</sup>" );
return(stmt1);
}


And for the options,
it have to parse the options n "parseOption" function.



int mainForm::parseOption(int ind,QString option, QString &stmt1, QString &phrase)
{
QTextStream cout(stdout, QIODevice::WriteOnly);
int j = 0;
int index = ind;
cout<<"311 : parseOption : option======="<<option<<endl;
cout<<"index&&\n"<<index<<endl;
cout<<"stmt1====\n"<<stmt1<<endl;
while(option[index] != '|')
{
stmt1[j] = option[index];
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;
if(option[index]=='\0')
{
// stmt1[j] = '\0';
cout<<"stmt1[j]\n"<<stmt1[j]<<endl;
// option[0] = '\0';
cout<<"option[0]\n"<<option[0]<<endl;
return -1;
}
index++;
j++;
}
// stmt1[j] = '\0';
cout<<"stmt1[j]**&\n"<<stmt1[j]<<endl;
stmt1=stmt1.replace( "{sub}","<sub>");
stmt1=stmt1.replace( "{/sub}","</sub>" );

cout<<"425 : "<<stmt1<<endl;
j = 0;
index++;
while(option[index] != '\\')
{
phrase[j] = option[index];
index++;
j++;
}
phrase=phrase.replace( "{sub}","<sub>" );
phrase=phrase.replace( "{sub}","<sub>" );
cout<<"Phrase value"<<phrase<<endl;
phrase[j] = '\0';
cout<<"436 : "<<phrase<<endl;

return (index + 1);

}


But in the "parseOption" function also it is parsing the questions itself.
I am compiling my code in "debug" mode only
Do you have any idea why it is parsing like this, and please tel me if any changes to be done in code

gayathrisekaran
9th November 2012, 12:50
The "baseFillChoose" is a class and is just to declare the pageno etc...



class baseFillChoose: public base
{
public:
QString stmt[2];
QString options[150];
QString voiceovers[150];
QString misc[150];
QString mgif[150];
QString mgif1[150];
int ptno[150];
QString chapter;
QString Queswav;
QString Queslist;
QString ChooseType;
int pageNo,qNo,correctNo;
int apno[150];
int qnumber;
QString stepno[150];
QString stepval[150];
baseFillChoose();
virtual bool checkFilled();
virtual int getNumStmt();
virtual int getNumOpt();
virtual int getNumVoiceOvers();
virtual int getNumMisc();
virtual int getNumMgifs();
virtual int getNumMgifs1();

virtual ~baseFillChoose();

};

/* fillups class */
class FillUps : public baseFillChoose {};

/* choose class */
class Choose : public baseFillChoose{};

/* short answers class */
class Short : public baseFillChoose
{

};

/* long answers class */
class Long : public baseFillChoose
{

};


/* match class */
class basematch : public baseFillChoose
{
public:

QString word[2];
QString matchword[2];
QString matchid[2];
QString voiceovers[2];
QString mgif[2];
QString mgif1[2];
QString ChooseType;
QString Queswav;
basematch();

virtual bool checkFilled();
virtual bool checkMatchFilled();
virtual int getNumStmt();
virtual int getNumOpt();
virtual int getNumVoiceOvers();
virtual int getNumMgifs();
virtual int getNumMgifs1();
virtual ~basematch();
};

class Match : public basematch{};


The following code is in same file commitdb.cpp.



case SHORT:
object = new Short(); // store the values from dom tree to objects
((baseFillChoose *)object)->pageNo = pageNo;
((baseFillChoose *)object)->ChooseType = ChooseType;
((baseFillChoose *)object)->Queswav = Queswav;
((Short *)object)->qnumber = qnumber;
((Short *)object)->stmt[0]="";
((Short *)object)->stmt[0] = ((listListNodes.item(0).cloneNode()).firstChild()) .nodeValue();
((Short *)object)->mgif[0] = (((listListNodes.item(0)).cloneNode()).toElement() ).attribute("mgif");
((Short *)object)->mgif1[0] = (((listListNodes.item(0)).cloneNode()).toElement() ).attribute("mgif1");
((Short *)object)->misc[0] = (((listListNodes.item(0)).cloneNode()).toElement() ).attribute("misc");
/*getting options*/

i = 0;
cout<<"172: enter..... SHort\n";
while(i<listListNodes.count())
{
((Short *)object)->options[i] = ((listListNodes.item(i)).cloneNode()).firstChild() .nodeValue();
((Short *)object)->voiceovers[i+1] = (((listListNodes.item(i)).cloneNode()).toElement() ).attribute("voiceover");
((Short *)object)->mgif[i+1] = (((listListNodes.item(i)).cloneNode()).toElement() ).attribute("mgif");
((Short *)object)->mgif1[i+1] = (((listListNodes.item(i)).cloneNode()).toElement() ).attribute("mgif1");
((Short *)object)->misc[i+1] = (((listListNodes.item(i)).cloneNode()).toElement() ).attribute("misc");
((Short *)object)->ptno[i+1] = (((listListNodes.item(i)).cloneNode()).toElement() ).attribute("ptno").toInt();
((Short *)object)->apno[i+1] = (((listListNodes.item(i)).cloneNode()).toElement() ).attribute("apno").toInt();
i++;
}
object->stmtStartPara = 0;
object->optStartPara = object->getNumStmt() + 1;
object->endPara = object->optStartPara + object->getNumOpt();

break;

ChrisW67
10th November 2012, 06:08
I am using Qt4.6.2.
While debugging, i am getting like this



The following is the exact piece of code where it points, When clicking ok.


inline QCharRef QString::operator[](int i)
{ Q_ASSERT(i >= 0); return QCharRef(*this, i); } // here it points


filename is qstring.h
Is there anything wrong in that.

No, there's nothing wrong with that. It is perfectly sane code that defends against being given bad inputs. The thing is, that is not your code. You seem to have missed this bit about the call stack:


The first line is the last bit of code to execute, the line after that is where that block of code was called form, the line after that is where that block of code was called from etc... Read down the list until the first line that is in one of your source files. That is where your problem started. In Qt Creator you can double-click on that line and the "Locals and expressions" will display all the variables in scope at that time... find the problem here.

Rather than post your entire program and expect someone else to work out where the problem is use the tools you already have to isolate the problem. We have already told you what the likely problem type is.

gayathrisekaran
12th November 2012, 04:36
No no its not like that guru. I am not expecting someone to check the problem.
I was seeking the help,
I'm debugging it and trying to find out .
What i thought is if you have come across the same piece of code then it would be helpful to me.
So i pasted the code.

gayathrisekaran
22nd November 2012, 04:54
I checked my code and did some corrections.

Instead of returning index value as -1



return -1;

I returned the index itself



return (index);


Also in the case SHORT:
Instead of checking the condition for executing query for inserting into answer table,



if(index=-1)

I checked the condition,



if((((Short *)object)->options[i])[index]!='\0')


Now it is working fine and all the questions and answers are entering to the main xml file also to the database in the appropriate table.

Thanks a lot Santosh Reddy and ChrisW67 for your useful posts.
Thanks & Regards

d_stranz
25th November 2012, 01:25
Why on earth are you doing all this casting of your Short * object to Short * and baseFillChoose * all over the place? Do you not understand how inheritance works in C++? You created a Short * instance. Just use it without all the casting. It makes your code almost incomprehensible.

And the long strings of method().method().method().method()... calls are guaranteed to cause you a big headache if one of those calls in the middle returns something unexpected and the rest of the calls fall apart as a result. Look at how long it took you to find the problem in your original post.

Please, do not work on any defence-related projects until you get a better understanding of C++. The world will be a safer place.

gayathrisekaran
26th November 2012, 03:13
No d_stranz, i haven't did the code. Before 7years someone did this code in qt3. Now i was supposed to do the same in qt4. For the past 2months i was trying to solve the problem. If i did it means surely i wont write this much complicated code as a beginner. Anyway i wont write such a complicated code until i completely understand and wellversed in c++. Thank you d_stranz. :)