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
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
Last edited by gayathrisekaran; 8th November 2012 at 05:20.
Refer this CallStack.jpg
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
gayathrisekaran (8th November 2012)
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: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);
}
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
Last edited by gayathrisekaran; 8th November 2012 at 08:35. Reason: updated contents
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?Qt Code:
{ ... 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++; } ... }To copy to clipboard, switch view to plain text mode
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
gayathrisekaran (8th November 2012)
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: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);
}
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![]()
Last edited by gayathrisekaran; 8th November 2012 at 13:01. Reason: updated contents
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])
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
sorry
Qt Code:
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; 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;To copy to clipboard, switch view to plain text mode
Qt Code:
{ 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); }To copy to clipboard, switch view to plain text mode
Qt Code:
{ cout<<"It is coming inside the parse function"<<endl; stmt1=stmt1.replace( "{sub}","<sub>" ); stmt1=stmt1.replace( "{/sub}","</sub>" ); stmt1=stmt1.replace( "{sup}","<sup>" ); stmt1=stmt1.replace( "{/sup}","</sup>" ); return(stmt1); }To copy to clipboard, switch view to plain text mode
Last edited by gayathrisekaran; 8th November 2012 at 16:35. Reason: updated contents
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...
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
gayathrisekaran (9th November 2012)
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: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
the value of 'i' is negative. This is exactly the sort of thing Santosh has been asking you to consider.Qt Code:
x = string[i]; // or x = string.at(i);To copy to clipboard, switch view to plain text mode
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.But the same code finely runs in qt3.
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.will you please explain what is call stack.
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)
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.
The inferior stopped because it received a signal from the Operating system
Signal name : SIGABRT
Signal meaning : Aborted
Qt Code:
{ Q_ASSERT(i >= 0); return QCharRef(*this, i); } // here it pointsTo copy to clipboard, switch view to plain text mode
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.
Qt Code:
{ cout<<"It is coming inside the parse function"<<endl; stmt1=stmt1.replace( "{sub}","<sub>" ); stmt1=stmt1.replace( "{/sub}","</sub>" ); stmt1=stmt1.replace( "{sup}","<sup>" ); stmt1=stmt1.replace( "{/sup}","</sup>" ); return(stmt1); }To copy to clipboard, switch view to plain text mode
And for the options,
it have to parse the options n "parseOption" function.
Qt Code:
{ 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); }To copy to clipboard, switch view to plain text mode
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
Last edited by gayathrisekaran; 9th November 2012 at 09:07. Reason: updated contents
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:
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.Originally Posted by Me
gayathrisekaran (10th November 2012)
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.
Last edited by gayathrisekaran; 12th November 2012 at 04:46. Reason: updated contents
The "baseFillChoose" is a class and is just to declare the pageno etc...
The following code is in same file commitdb.cpp.Qt Code:
class baseFillChoose: public base { public: int ptno[150]; QString chapter; QString Queswav; QString Queslist; QString ChooseType; int pageNo,qNo,correctNo; int apno[150]; int qnumber; 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 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{};To copy to clipboard, switch view to plain text mode
Qt Code:
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;To copy to clipboard, switch view to plain text mode
Bookmarks