1 Attachment(s)
Thread Search in text file large
Hi everyone. :)
I need a system that searches of large text files, you must have a main form and a search form that runs on a different thread because it freezes the system. I must also open up new forms of search that works simultaneously and I can stop, pause and restart the search.
Main Form - frmTelaPrincipal.cpp
Code:
void clsTelaPrincipal::on_actionCadastro_de_Clientes_tr iggered()
{
clsCadClientes *objfrmCadClientes = new clsCadClientes;
ui->mdiArea->addSubWindow(objfrmCadClientes);
objfrmCadClientes->show();
Search Form - frmCadClientes.cpp
Code:
void clsCadClientes::on_cmdTextEdit_clicked()
{
Open file routine here...
ui->txtEdit->setPlainText(in.readAll());
file.close();
}
}
void clsCadClientes::on_cmdSearch_clicked()
{
while (ui->txtEdit->find(ui->lineEdit->text()))
{
ui->txtEdit->setTextBackgroundColor("yellow");
}
How do I post the source code?
marcos.miranda
msn: jmbm.trab@bol.com.br
Re: Thread Search in text file large
And what do you want us to do with what you posted?
Re: Thread Search in text file large
Hi, wysota
As you may have gathered, I am a beginner in QT Framework and C + +, I'm lost with this new language. Thanks for responding.
First explain to me how do I post to blocks of text like you did.
QT Code:
Second
Regarding your question and I posted, as I open the form (Search Form - frmCadClientes.cpp) in another thread and it works without freezing the main form and other forms open.
Posted the source code to facilitate for those who help me and I understand when the solver put it back in response to the problem.
Thank you for your attention.
Re: Thread Search in text file large
Quote:
Originally Posted by
marcos.miranda
First explain to me how do I post to blocks of text like you did.
You place [code] and [/code] tags around your code.
Quote:
Regarding your question and I posted, as I open the form (Search Form - frmCadClientes.cpp) in another thread and it works without freezing the main form and other forms open.
You can't access widgets from within worker threads. This will crash your program.
Quote:
Posted the source code to facilitate for those who help me and I understand when the solver put it back in response to the problem.
The thing is you didn't say what the problem was.
2 Attachment(s)
Re: Thread Search in text file large
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:
Code:
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();
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:
Code:
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();
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:
Attachment 7850
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
Attachment 7851
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.
Re: Thread Search in text file large
Quote:
Originally Posted by
marcos.miranda
When I press the Open File button and select the text file into a string search the system freezes.
The system or your program?
Quote:
When I start a search for a particular string in the text file back to the system freeze to end the search.
If by "the system" you mean your application, then it's quite normal since it takes some time for the while loop to execute.
Quote:
How do? I do not have no idea!
You can do the search in an external thread (but not on the QTextEdit object!!!) or you can let the application process events (using QCoreApplication::processEvents()) from time to time while searching. Note that probably there are faster algorithms than using QTextEdit::find().
Re: Thread Search in text file large
Hi, wysota
QCoreApplication :: processEvents (), I used inside the while loop has mitigated the problem, because i managed to open another form of search and start a new search simultaneously, was when I realized that this new form stopped interfering in the search form above to search old already open.
Is it possible when I call a new form of search it opens in a separate process of the program? How?
Thanks....
Re: Thread Search in text file large
I don't really understand what you mean. The term "process" has a concrete meaning when it comes to computers, I don't think you really meant that.
Re: Thread Search in text file large
Hi, wysota
Is it possible when I call a new form of search it opens in a separate Thread ?
How?
Thanks....
Re: Thread Search in text file large
No, forms don't open "in threads". You can do the search in a separate thread and display the results in a window.
Re: Thread Search in text file large
Hi everyone.
The QFile can open a file type. "Rtf and. Doc"?
How would the code if you can?
Thanks..
Re: Thread Search in text file large
A file is a file. QFile doesn't care about content of the file you use. If you want to ask whether you can import an rtf or doc document to QTextEdit, then no, you'd have to have a dedicated import component.