Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Program exited with code 0
Forum Update on Monday, May 27th 2025

[Solved]Program exited with code 0

Scheduled Pinned Locked Moved General and Desktop
49 Posts 3 Posters 29.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlekseyOk
    wrote on 15 Nov 2012, 07:26 last edited by
    #6
    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 :-))

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gayu
      wrote on 15 Nov 2012, 07:56 last edited by
      #7

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlekseyOk
        wrote on 15 Nov 2012, 08:13 last edited by
        #8

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

        E.g.:

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gayu
          wrote on 15 Nov 2012, 09:04 last edited by
          #9

          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.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlekseyOk
            wrote on 15 Nov 2012, 09:06 last edited by
            #10

            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

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gayu
              wrote on 15 Nov 2012, 09:16 last edited by
              #11

              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 Reply Last reply
              0
              • A Offline
                A Offline
                AlekseyOk
                wrote on 15 Nov 2012, 09:18 last edited by
                #12
                1. Is option a QString?
                2. Is option ends with '\0'?

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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gayu
                  wrote on 15 Nov 2012, 09:30 last edited by
                  #13

                  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.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AlekseyOk
                    wrote on 15 Nov 2012, 09:39 last edited by
                    #14

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

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gayu
                      wrote on 15 Nov 2012, 10:11 last edited by
                      #15

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

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        AlekseyOk
                        wrote on 15 Nov 2012, 10:25 last edited by
                        #16

                        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

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gayu
                          wrote on 15 Nov 2012, 10:33 last edited by
                          #17

                          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.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            gayu
                            wrote on 15 Nov 2012, 11:23 last edited by
                            #18

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

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              AlekseyOk
                              wrote on 15 Nov 2012, 12:08 last edited by
                              #19

                              add } before else

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                gayu
                                wrote on 15 Nov 2012, 12:23 last edited by
                                #20

                                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

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  AlekseyOk
                                  wrote on 15 Nov 2012, 12:26 last edited by
                                  #21

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

                                  1. Insert some values into some db?
                                  2. something else?
                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    gayu
                                    wrote on 15 Nov 2012, 12:34 last edited by
                                    #22

                                    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

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      AlekseyOk
                                      wrote on 15 Nov 2012, 12:37 last edited by
                                      #23

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

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        gayu
                                        wrote on 16 Nov 2012, 03:42 last edited by
                                        #24

                                        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.

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          gayu
                                          wrote on 16 Nov 2012, 05:30 last edited by
                                          #25

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

                                          @

                                          1 Reply Last reply
                                          0

                                          15/49

                                          15 Nov 2012, 10:11

                                          topic:navigator.unread, 34
                                          • Login

                                          • Login or register to search.
                                          15 out of 49
                                          • First post
                                            15/49
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved