nickb
19th October 2010, 23:59
I am trying to read in a group of words from a file, then select a random word. This is what I have, it makes sense to me logically, but obviously its wrong, because you cannot pull a QString from a QStringList. Yes, this is a homework assignment, but it is part of a very large project, a dictionary to be exact.
QFile inputFile("C:\\Users\\hisownfoot\\Documents\\Dictionary_3\\wo rdList_new.txt");
// Create an inputstream to handle the file
QTextStream in(&inputFile);
// Insert the text from the file into the QString dictionaryString
QString dictionaryString = in.readAll();
inputFile.close();
// Fills the QStringList with each word in the dictionary string, which are all
// seperated by 2 spaces.
wordList = dictionaryString.split(" ");
int n = wordList.size();
int random_selector;
random_selector = (rand()%n)+1;
QString gameword;
gameword = wordList.at(random_selector);
ui->textBox->append(gameword);
I receive a runtime error upon running this specific area of the program, and it causes it to crash.
Invalid parameter passed to C runtime function.
That is what appears in the application output, and using debugging i determined the line it goes bad at is,
gameword = wordList.at(random_selector);
QFile inputFile("C:\\Users\\hisownfoot\\Documents\\Dictionary_3\\wo rdList_new.txt");
// Create an inputstream to handle the file
QTextStream in(&inputFile);
// Insert the text from the file into the QString dictionaryString
QString dictionaryString = in.readAll();
inputFile.close();
// Fills the QStringList with each word in the dictionary string, which are all
// seperated by 2 spaces.
wordList = dictionaryString.split(" ");
int n = wordList.size();
int random_selector;
random_selector = (rand()%n)+1;
QString gameword;
gameword = wordList.at(random_selector);
ui->textBox->append(gameword);
I receive a runtime error upon running this specific area of the program, and it causes it to crash.
Invalid parameter passed to C runtime function.
That is what appears in the application output, and using debugging i determined the line it goes bad at is,
gameword = wordList.at(random_selector);