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(); } }
-
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' -
@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:
Already solved the problem)
would you mind sharing the solution?
in addition, please don't forget to mark your post as solved!
-
@Pablo-J-Rogina
Yes, of course. All i had to do was add "append" :)for (QChar &item : vowels) { ui->textEdit_2->append(item); }