[Solved]Program exited with code 0
-
Hi,
I am new to Qt. I am using Qtcreator version 4.6.2, in linux.
The main theme of my project is to prepare a question bank.
In that, through the editor i am entering the various options (i.e fill,choose,match,short ques,and long ques).
While entering through editor, the .xml file first generate and from that xml file it will enter the database.
In that the i’m having problem in entering short ques and long ques into the database.
While entering the Question and Answer,it generates the xml file bt nt enter to the database, and get exit from the editor showing the following.@
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
@
please help me to solve this. -
The index is initialized to '0'.
Some formats are there to enter the Question and Answers in Database, through editor.
While the Question is entered the parseQuestion function is called.
While the Answer is entered the parseOption function is called.
In the parseOption function, the condition is checked. The function includes the index,option,stmt,phrase .
The phrase is the one entered within the '| ' (eg |Lotus\ is our national flower) In this eg to highlight "Lotus" we are using the '| ' symbol.
In the above eg Lotus is the phrase, if any stmt seen before the phrase is considered as stmt1,and after the phrase is the stmt2.I give another eg.
If i am entering a Ques and Ans like this
What is Qt?
Qt is a |cross platform application framework
Qt is a is the stmt1
*|cross platform application framework* is the phraseWhile running with above eg my code runs fine and every thing enters into the database.
But when i am entering like this
What is Qt?
Qt is a |cross platform application framework\ .
Qt is a is the stmt1
*|cross platform application framework* is the phrase
.. is considered as the stmt2 and returns the index value as '-1' since there is no '|'
The following is the condition it checks for the stmt2, and no '|' is seen so returning '-1'until for stmt1 amd the phrase it reads the index value as +ve value only.
bt when reading the stmt2 it is returning '-1'.@
while(option[index] != '|')
{
stmt1[j] = option[index];
cout<<"stmt1[j]\n"<<stmt1<<endl;
if(option[index]=='\0')
{
stmt1[j] = '\0';
option[0] = '\0';
return -1; //here it returns '-1'
}
index++;
j++;
}
@ -
I used some cout stmts to check wat the option of index is.
The option[index] is printing as the "|" symbol.
After the stmt1 the "|" is seen and return the option[index] as "|" and returning the index value as +ve value.
Then when coming to the stmt2 it checks the condition, "|" . The condition is not get satisfied returning "-1".And I also tried wat u said,
@
1.
while(option[index] != '|' &&
2.
option[index] != '\0')
@
It is not taking the phrase value,only it reads the stmt1, and exit from the editor. -
try to add you check
@
if(option[index]=='\0')
{
stmt1[j] = '\0';
option[0] = '\0';
return -1; //here it returns '-1'
}
@after the loop if you want to exit with code -1.
Why are you using this loop instead of "QString::indexOf":http://qt-project.org/doc/qt-4.8/qstring.html#indexOf
-
-
By trying with this code,
@
1.int pos1 = option.indexOf('|');
2.if (pos1 != -1)
3. {
4. stmt1 = option.left(pos1);
5. int pos2 = option.indexOf('\', pos1);
7. if (pos2 != -1)
8. {
9. phrase = option.mid(pos1, pos2 - pos1);
10 }
11. else
12. {
13. // there is no '|' symbol in option
14. }
@
I am getting this error "commitdb.cpp:1219: error: a function-definition is not allowed here before ‘{’ token" in some other functions.
so i removed this code and compile with the the original code itself.@@ -
Ya i added }
Now it is not exiting from the editor and its working.
But, the question is entering into database finely, the answer is not entering to the database (i.e options) printing the null values for option,stmt1 and stmt2 . Also the null values are entering to database more than once