Text processing in QTextEdit
- 
Hi! 
 I Made it possible to take text from a file and encountered a problem:
 I need to find and output in reverse alphabetical order the vowel letters from each line.
 Most likely, i need to solve this through an array of characters to take from the string. But how to implement it?void MainWindow::on_pushButton_clicked() { QFile file("F:/Labs/Text/Text.txt"); if(file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); QString str = stream.readAll(); ui->textEdit->setText(str); file.close(); } }
- 
I don't understand your need. 
 But if you want to read the file line by line, you could usewhile(!stream.atEnd()) { str = stream.readLine(); ui->textEdit->append(str); }
- 
@Bonnie I took the text from a file and put it in QTextEdit, and now I need to somehow output in reverse alphabetical order the vowel letters from each line of this text 
- 
Hi 
 If i understood correctly then something like this.void Test() { QString line("the hens ate the wolves under the brigde"); QList<QChar> vowels; for (int i = 0; i < line.length(); ++i) { QCharRef letter(line[i]); if ( letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u' || letter == 'A' || letter == 'E' || letter == 'I' || letter == 'O' || letter == 'U') { vowels.push_back(letter); } } std::sort( vowels.begin(), vowels.end(), [](QChar & p1, QChar & p2) { return p1 > p2; } ); for (QChar &item : vowels) { qDebug() << "=" << item; } }= 'u' 
 = 'o'
 = 'i'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'a'
- 
Hi 
 If i understood correctly then something like this.void Test() { QString line("the hens ate the wolves under the brigde"); QList<QChar> vowels; for (int i = 0; i < line.length(); ++i) { QCharRef letter(line[i]); if ( letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u' || letter == 'A' || letter == 'E' || letter == 'I' || letter == 'O' || letter == 'U') { vowels.push_back(letter); } } std::sort( vowels.begin(), vowels.end(), [](QChar & p1, QChar & p2) { return p1 > p2; } ); for (QChar &item : vowels) { qDebug() << "=" << item; } }= 'u' 
 = 'o'
 = 'i'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'e'
 = 'a'
- 
@Troyer 
 Np, do note that is not the most pretty way. the vowels could be in a list and so on and we use
 QChar to store it which might be overkill if only ascii but for a smaller text file it wont really matter.@mrjj Hello again! 
 I still find it difficult to analyze your code, I'm not professional enough yet :)
 And I would like to ask you one more question. I need to output all characters in QTextEdit, not in the app console (you use QDebug for this)
 I tried converting all the characters to a string and then just output the text: ui - >textEdit - >setText(str), but failed. What should I do now?
 (Sorry for my English, not my main one)
- 
@mrjj Hello again! 
 I still find it difficult to analyze your code, I'm not professional enough yet :)
 And I would like to ask you one more question. I need to output all characters in QTextEdit, not in the app console (you use QDebug for this)
 I tried converting all the characters to a string and then just output the text: ui - >textEdit - >setText(str), but failed. What should I do now?
 (Sorry for my English, not my main one)@Troyer said in Text processing in QTextEdit: but failed In what way failed? What happened? Can you show the code? 
- 
@Troyer said in Text processing in QTextEdit: but failed In what way failed? What happened? Can you show the code? 
- 
@Troyer said in Text processing in QTextEdit: Already solved the problem) would you mind sharing the solution? in addition, please don't forget to mark your post as solved! 
- 
@Troyer said in Text processing in QTextEdit: Already solved the problem) would you mind sharing the solution? in addition, please don't forget to mark your post as solved! 
 

