hi, (first of all, i dont have a good english so hope u understand)
i ve a prob with reading the data from a file, in fact i must create a multiple choice question program and i have finished the phase of writing to a file in this format.
Geography
2 //number of questions
Which one is the capital of India?
Paris
0
New Delhi
1
Frankfurt
0
Mumbai
0
Which one is the capital of France?
Paris
1
Jakarta
0
New York
0
Kabul
0
and for readin this file , i have done something like this:
QFile file (filename);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::Warning(this, "Application","can not open the file");
}
QTextStream in (&file);
QString mcqnameQString = in.readLine();
string mcqnameString = mcqQString.toStdString(); // i change the QString to String //cause i transfer it to a c++ class that i ve created
int nbQuestion;
in >> nbQuestion; // i want to put 2 in nbQuestion and go to the newline but i think this method doesnot let me to go to the next line of Stream, and i dont want to use a readLine() methode cause, it returns the line as QString but i want it as integer
quest = new Questionnaire(mcqnameString, nbQuestion); // my c++ class where i //should save all the stream that i read
for (int i=0; i<nbQuestion; i++)
{
QString questionQString = in.readLine();
string questionString = questionQString.toStdString();
quest -> tabquestion[i].setQuestion(questionString);
for (int j=0; j<4; j++)
{
QString responsQString = in.readLine();
string responsString = responsQString.toStdString();
quest -> tabquestion[i].tabrespons[j].setRespons(responsString);
int state; // same probleme as for saving the nbQuestion mentioned
in >> state; //on top
quest -> tabquestion[i].tabrespons[j].setStateRespons(state);
}
}
my problem is that doing this i get a segmentation error, i know the problem comes with the (in >> ) operator, cause i think after putting the data on the integer variables , it does not go to the next line as it is the case of the readLine() i guess. cause if i put all of them as readLine(), i does not get an error, but i dont want it like that, i want to have the integers as integer and the text as text...
pls help me ..
Bookmarks