How to get lines from a file using editText
-
wrote on 2 Dec 2019, 19:14 last edited by
Hello everyone!
here, iam trying to read all the lines from my file into qt textEdit but iam facing problems in calling the ReadAllWords function and setText!
here is my code, i think iam close, because i did it a long time ago but i totally forgot.
Thanks!void delete1::on_showlines_clicked() { Quizlet quizlet; //creating an object of class Quizlet //quizlet.ReadAllWords(); //calling the function ReadAllWords ui->textEdit->setText(quizlet.ReadAllWords()); }
-
Hello everyone!
here, iam trying to read all the lines from my file into qt textEdit but iam facing problems in calling the ReadAllWords function and setText!
here is my code, i think iam close, because i did it a long time ago but i totally forgot.
Thanks!void delete1::on_showlines_clicked() { Quizlet quizlet; //creating an object of class Quizlet //quizlet.ReadAllWords(); //calling the function ReadAllWords ui->textEdit->setText(quizlet.ReadAllWords()); }
wrote on 2 Dec 2019, 19:22 last edited by@LordHomie said in How to get lines from a file using editText:
but iam facing problems in calling the ReadAllWords function and setText!
Always helps if you say what problems, or do you think we should be able to guess?
-
@LordHomie said in How to get lines from a file using editText:
but iam facing problems in calling the ReadAllWords function and setText!
Always helps if you say what problems, or do you think we should be able to guess?
wrote on 2 Dec 2019, 19:49 last edited by LordHomie 12 Feb 2019, 19:50@JonB said in How to get lines from a file using editText:
am facing problems in calling the ReadAllWords function and setText!
LoL, i think i mentioned already.
well, this is my code for ReadAllWords function to print all the lines from the file:
vector<string> Quizlet::ReadAllWords() { // File pointer fstream fin; fin.open("words.txt", ios::in); vector <string> rows; string line, word, temp; while (getline(fin, line)) { rows.push_back(line); stringstream s(line); } return rows; }
and in another source file i want to call the ReafAllFunction into editText,
i hope this helps -
@JonB said in How to get lines from a file using editText:
am facing problems in calling the ReadAllWords function and setText!
LoL, i think i mentioned already.
well, this is my code for ReadAllWords function to print all the lines from the file:
vector<string> Quizlet::ReadAllWords() { // File pointer fstream fin; fin.open("words.txt", ios::in); vector <string> rows; string line, word, temp; while (getline(fin, line)) { rows.push_back(line); stringstream s(line); } return rows; }
and in another source file i want to call the ReafAllFunction into editText,
i hope this helpswrote on 2 Dec 2019, 20:03 last edited by JonB 12 Feb 2019, 20:06LoL, i think i mentioned already.
You said there was a problem, but nothing about what it is. Nothing like an error message.
So if it's
vector<string> Quizlet::ReadAllWords()
presumably you need to convert that list of strings into something compatible with
setText(const QString &)
? Maybe you want to rejoin the lines with\n
?
1/4