[Solved]Program exited with code 0
-
wrote on 15 Nov 2012, 09:30 last edited by
ya the option is QString only.
You asked me to check the "if" by adding it after the loop. By adding it after the loop only becomes infinite. -
wrote on 15 Nov 2012, 09:39 last edited by
Should this help?
@
int pos1 = option.indexOf('|');
if (pos1 != -1)
{
stmt1 = option.left(pos1);int pos2 = option.indexOf('\\', pos1); if (pos2 != -1) { phrase = option.mid(pos1, pos2 - pos1); }
else
{
// there is no '|' symbol in option
}
@ -
wrote on 15 Nov 2012, 10:11 last edited by
Ya i tried tis by replacing tat, bt it is still the same not exiting from the loop, also printing the stmt as null.
-
wrote on 15 Nov 2012, 10:25 last edited by
You shouldn't use a single backslash in option string, because it will be processed as '.' in second case.
So, before processing, replace single backslashes with doubled or select another symbol -
wrote on 15 Nov 2012, 10:33 last edited by
This means whether you are asking me to use double backslash in the phrase itself or at the end of last stmt i've to put double backslash.
-
wrote on 15 Nov 2012, 11:23 last edited by
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.@@ -
wrote on 15 Nov 2012, 12:08 last edited by
add } before else
-
wrote on 15 Nov 2012, 12:23 last edited by
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 -
wrote on 15 Nov 2012, 12:26 last edited by
Sorry, I don't understand what you do you want.
- Insert some values into some db?
- something else?
-
wrote on 15 Nov 2012, 12:34 last edited by
no through editor i am entering the Ques and answer also
The xml file generates, from the xml file to database it is entering, bt the Ques is entering into the database correctly.
The options i.e Qt is a |cross platform\ appln framework is the Answer stmt.
Bt this enters the database as null value only not the stmt or phrase -
wrote on 15 Nov 2012, 12:37 last edited by
My code is not processing statements with asterisk (*), so you should add this by yourself ;-)
-
wrote on 16 Nov 2012, 03:42 last edited by
No thats not my problem.
After replacing my code with the code wat u give me to replace with, the following is the table entries now.
The following table for Question entries
QNo | Question | QueLocLang | Board | Subject | Chapter | PageNo
4724 | What is Qt? | NULL | Tamil Nadu | EnglishI | 1 | 1
4725 | Who is Sachin? | NULL | Tamil Nadu | EnglishI | 1 | 1
The table entries for Answers is,
More than one time it is entering like the followingAPNo | Statement1 | Statement2 | Option1 | QNo
80563 | | NULL | | 4724
80564 | | NULL | | 4724
80565 | | NULL | | 4724
80566 | | NULL | | 4725
80567 | | NULL | | 4725
80568 | | NULL | | 4725
The actual Answer table should be like,
APNo | Statement1 | Statement2 | Option1 | QNo
80563 | Qt is a | NULL | cross platform application framework | 4724
80564 | | is sachin | A famous crickter | 4725
But i am not getting like this. I am just getting the empty values for stmt1,option.
-
wrote on 16 Nov 2012, 05:30 last edited by
Instead of 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<<"index---\n"<<index<<endl;
cout<<"311 : parseOption : "<<option<<endl;
cout<<"option[index]--\n"<<option[index]<<endl;
while(option[index] != '|')
{
stmt1[j] = option[index];
cout<<"stmt1[j]\n"<<stmt1<<endl;
if(option[index]=='\0')
{
cout<<"option[index]-----\n"<<option[index]<<endl;
stmt1[j] = '\0';
option[0] = '\0';
return -1;
// return (index);
}
index++;
j++;
}
stmt1[j] = '\0';
stmt1=stmt1.replace( "{sub}","<sub>");
stmt1=stmt1.replace( "{/sub}","</sub>" );while(option[index] != '\')
{
phrase[j] = option[index];
index++;
j++;
}cout<<"425 : "<<stmt1<<endl;
j = 0;
index++;
cout<<"option[index]-->\n"<<option[index]<<endl;
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);
}
@I added the code u asked me to add
@
-
int pos1 = option.indexOf('|');
-
if (pos1 != -1)
-
{
-
stmt1 = option.left(pos1);
-
int pos2 = option.indexOf('\\', pos1);
-
if (pos2 != -1)
-
{
-
phrase = option.mid(pos1, pos2 - pos1);
-
}
-
else
- {
- // there is no '|' symbol in option
-
}
@
-
-
wrote on 16 Nov 2012, 07:01 last edited by
I've already checked my code and it works fine (actually, you can change line 9 with phrase = option.mid(pos1 + 1, pos2 - pos1); to remove leading '|').
Input: "Qt is a |cross platform application framework."
Output: stmt1 = "Qt is a "
phrase = ""cross platform application framework" -
wrote on 16 Nov 2012, 10:06 last edited by
I tried by that too phrase = option.mid(pos1 + 1, pos2 – pos1); bt nw th answer table is not get updated.
i.e the Questions are entering to the database, but the answers are not entering to the database in answer table. -
wrote on 16 Nov 2012, 10:14 last edited by
@
QString option = "Qt is a |cross platform application framework\.";
int pos1 = option.indexOf('|');
if (pos1 != -1)
{
stmt1 = option.left(pos1);int pos2 = option.indexOf('\\', pos1); if (pos2 != -1) { phrase = option.mid(pos1, pos2 - pos1 + 1); }
}
else
{
qDebug("there is no '|' symbol in option");
}qDebug("stmt1=%s, phrase=%s", qPrintable(stmt1), qPrintable(phrase));
@Output: "stmt1=Qt is a , phrase=|cross platform application framework"
Is this output correct for your task?
-
wrote on 16 Nov 2012, 11:28 last edited by
The '|' and '' should not seen in the database. Otherwise the output is correct.
But, the thing is i need the stmt2 also enter to the database.
for eg|Lotus\ is our national flower.
In the above stmt, lotus is the phrase, and is our national flower is the stmt2.
That stmt2 is not entering in database.And also tried with that code, also remain the same problem, the answers are not entering into the database.
-
wrote on 16 Nov 2012, 12:52 last edited by
try to replace '' with '\'
-
wrote on 19 Nov 2012, 06:09 last edited by
ya i tried by replacing '' with '\' Still it is not get inserting into the Answer table.
-
wrote on 19 Nov 2012, 06:18 last edited by
So in my code instead of return -1, i replaced it by returning the index as return index.
As in the switch case, in if condition i'm checking the condition as
@
if(option[index]=='\0')
{
cout<<"option[index]-----\n"<<option[index]<<endl;
stmt1[j] = '\0';
option[0] = '\0';
//return -1; instead of this
return (index); added this
}
@instead of this condition i replaced it as,
@
if(index!=-1) instead of thisif((((Short *)object)->options[i])[index]!='\0') added this
{
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)");
}
@With the above condition what i've added it working fine.
It is inserting into the Ques table and also in Ans table now. whether it is right or nt. Do you have any idea about this. Please tell me
22/49