[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.



  • Your index to operator[] is invalid (< 0).



  • sorry to ask might be a silly Question.
    What "index to operator[] is invalid (< 0)" this mean



  • This means that you are trying to make something like this:

    @
    QVector<int> vec;
    vec[-1] = 0;
    @



  • ya, in my code it is returning the index value "index=-1". so it is exiting.
    It should not return the "-1". I am trying to solve, bt i dont know how to solve this. please help me



    1. Find error in your code
      or/and
    2. Check for correctness your index @(index >= 0 && index < vec.size())@ before operator[]

    if (index == -1) is an exit condition - just exit from your app :-))



  • 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 phrase

    While 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++;
    }
    @



  • You should check for '|' and NOT '\0'.

    E.g.:

    @
    while(option[index] != '|' &&
    option[index] != '\0')
    @



  • 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



  • Ya i checked by adding the "if" after the loop.
    But it doesn't exit from the loop, runs until i stop the execution.



    1. Is option a QString?
    2. Is option ends with '\0'?

    If 1 and 2 are true than this loop shouldn't be infinite.



  • 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.



  • 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
    }
    @



  • Ya i tried tis by replacing tat, bt it is still the same not exiting from the loop, also printing the stmt as null.



  • 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



  • 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.



  • By trying with this code,

    @
    1.int pos1 = option.indexOf('|');
    2.if (pos1 != -1)

    1.  {
      
    2.      stmt1 = option.left(pos1);
      
    3.      int pos2 = option.indexOf('\\', pos1);
      
    4.      if (pos2 != -1)
      
    5.      {
      
    6.          phrase = option.mid(pos1, pos2 - pos1);
      

    10 }

    1.  else
      
    2.  {
      
    3.      // there is no '|' symbol in option
      
    4.  }
      

    @
    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.@@



  • add } before else



  • 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



  • Sorry, I don't understand what you do you want.

    1. Insert some values into some db?
    2. something else?


  • 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



  • My code is not processing statements with asterisk (*), so you should add this by yourself ;-)



  • 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 following

    APNo | 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.



  • 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

    @

    1.  int pos1 = option.indexOf('|');
      
    2.  if (pos1 != -1)
      
    3.  {
      
    4.    stmt1 = option.left(pos1);
      
    5.      int pos2 = option.indexOf('\\', pos1);
      
    6.      if (pos2 != -1)
      
    7.      {
      
    8.          phrase = option.mid(pos1, pos2 - pos1);
      
    9.      }
      
    10. else
      
    11. {
    12. // there is no '|' symbol in option
    13.  }
      

    @



  • 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"



  • 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.



  • @
    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?



  • 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.



  • try to replace '' with '\'



  • ya i tried by replacing '' with '\' Still it is not get inserting into the Answer table.



  • 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 this

    if((((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



  • What is an "Answer table"?! We didn't speak about any insertion of data to Answer table. Check your SQL-queries for correctness.



  • The answer table is where the options and stmt get parsed i.e Qt is a |Cross platform appln framework. is to be in the answer table.
    Surely i'll check the SQL-queries where i've to do the corrections.



  • First of all - print all values on the screen
    Second - change SQL-query builder to the next:

    @
    query = new QSqlQuery("insert into ShAnsPts(Statement1,Statement2,Option1,QNo,PointNo,CorrectNo) values (?, ?, ?, ?, ?, ?)");
    query.addBindValue(stmt1);
    query.addBindValue(QVariant(QVariant::String)); // NULL string
    query.addBindValue(phrase);
    query.addBindValue(temp2.setNum(qNo));
    query.addBindValue(temp2.setNum(((Short *)object)->ptno[i+1]));
    query.addBindValue(1);
    @



  • Sorry for asking you again and again, please tell me
    Instead of the following code
    @
    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)");
    @

    I've to add this code
    @
    query = new QSqlQuery("insert into ShAnsPts(Statement1,Statement2,Option1,QNo,PointNo,CorrectNo) values (?, ?, ?, ?, ?, ?)");
    query.addBindValue(stmt1);
    query.addBindValue(QVariant(QVariant::String)); // NULL string
    query.addBindValue(phrase);
    query.addBindValue(temp2.setNum(qNo));
    query.addBindValue(temp2.setNum(((Short *)object)->ptno[i+1]));
    query.addBindValue(1);
    @

    If means by adding this code it is showing the error as request for member ‘addBindValue’ in ‘query’, which is of non-class type ‘QSqlQuery

    For printing the values on screen i already added the following code.

    35 = parseOption(index,((Short *)object)->options[i],stmt1,phrase);
    cout<<"index : "<<index<<"\n"<<stmt1<<"\n"<<phrase<<endl;
    QString text11;
    stmt1temp=stmt1;
    cout<<"stmt1temp\n"<<stmt1<<endl;
    stmt1=stmt1temp;
    cout<<"stmt1\n"<<stmt1<<endl;
    phrasetemp=phrase;
    cout<<"phrasetemp\n"<<phrasetemp<<endl;
    phrase=phrasetemp;
    cout<<"phrase\n"<<phrase<<endl;@



    1. change '.' to '->'
    2. What is an output of cout << *?


  • index : 41
    Qt is a
    cross platform appln framework
    stmt1temp
    .
    stmt1
    .
    phrasetemp
    cross platform appln framework
    phrase
    cross platform appln framework



    1. As I can see your output doesn't contain any NULL-value. So, I think you have errors somewere else... Possibly, in SQL-table (e.g. wrong field type).
    2. For what are you make such assignments:

    @
    ...
    stmt1temp=stmt1;
    cout<<"stmt1temp\n"<<stmt1<<endl;
    stmt1=stmt1temp;
    ...
    @
    ?



  • For eg if i am entering the answer like this.
    Android is a |Linux-based operating system\ designed primarily for touchscreen mobile devices.

    In the following code,
    @
    index = parseOption(index,((Short *)object)->options[i],stmt1,phrase);
    cout<<"index : "<<index<<"\n"<<stmt1<<"\n"<<phrase<<endl;
    @
    The stmt1temp,stmt1 is considered as Android is a
    As you know, the phrasetemp,phrase is the same Linux-based operating system
    By the following code,

    @
    stmt1=parseQuestion(stmt1); // function called for replacing tilde,cape symbol to angluar brackets
    cout<<"stmt1--\n"<<stmt1<<endl;
    stmt2temp=parseStepNo(stmt1,i,aPNo);
    cout<<"stmt2temp\n"<<stmt2temp<<endl;
    cout<<"\nThis is the apno value required"<<aPNo<<endl;
    stmt2=stmt2temp;
    cout<<"This is STatement2 value"<<stmt2<<endl;
    @

    The stmt1 is taken for stmt2 i.e designed primarily for touchscreen mobile devices.
    The assignments are mainly made for parsing the options.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.