Hi,
Frist problem
When I press the Open File button and select the text file into a string search the system freezes. The code executed is the following:
tr("Text Files (*.txt);;MSWord Files (*.doc)"));
if (fileName != "") {
QMessageBox::critical(this, tr
("Error"), tr
("Could not open file"));
return;
}
ui->txtEdit->setPlainText(in.readAll());
file.close();
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
tr("Text Files (*.txt);;MSWord Files (*.doc)"));
if (fileName != "") {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;
}
QTextStream in(&file);
ui->txtEdit->setPlainText(in.readAll());
file.close();
To copy to clipboard, switch view to plain text mode
How can this not happen?
Second problem
When I start a search for a particular string in the text file back to the system freeze to end the search. The code executed is the following:
int vnumLinhaInit,vnumLinhasTotal;
vnumLinhaInit=0;
vnumLinhasTotal = ui->txtEdit->document()->lineCount();
while (ui->txtEdit->find(ui->lineEdit->text()))
{
ui->txtEdit->setTextBackgroundColor("yellow");
ui
->lblContador
->setText
(QString::number( vnumLinhaInit
));
vnumLinhaInit += 1;
}
msgBox.setText("A Busca Terminou !!!");
msgBox.exec();
int vnumLinhaInit,vnumLinhasTotal;
vnumLinhaInit=0;
vnumLinhasTotal = ui->txtEdit->document()->lineCount();
ui->txtEdit->moveCursor(QTextCursor::Start);
while (ui->txtEdit->find(ui->lineEdit->text()))
{
ui->txtEdit->setTextBackgroundColor("yellow");
ui->lblContador->setText(QString::number( vnumLinhaInit ));
vnumLinhaInit += 1;
}
QMessageBox msgBox;
msgBox.setText("A Busca Terminou !!!");
msgBox.exec();
To copy to clipboard, switch view to plain text mode
How can this not happen?
As I understand my problem all forms are running in the same thread and have a heavy processing in both the opening of the text file as the moment of the search string in this large file system freezes. following drawing:
Thread Search 01.jpg
It could be done the following?
Run the search forms on different threads as in the main drawing below, so that the search processing can be without interfering with each other
Thread Search 02.jpg
How do? I do not have no idea!
If you or anyone has a solution to this freezing does not happen please post the code.
Thank you for your attention.
Bookmarks