Results 1 to 12 of 12

Thread: Thread Search in text file large

  1. #1
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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
    Qt Code:
    1. void clsTelaPrincipal::on_actionCadastro_de_Clientes_tr iggered()
    2. {
    3. clsCadClientes *objfrmCadClientes = new clsCadClientes;
    4. ui->mdiArea->addSubWindow(objfrmCadClientes);
    5. objfrmCadClientes->show();
    To copy to clipboard, switch view to plain text mode 

    Search Form - frmCadClientes.cpp
    Qt Code:
    1. void clsCadClientes::on_cmdTextEdit_clicked()
    2. {
    3. Open file routine here...
    4. ui->txtEdit->setPlainText(in.readAll());
    5. file.close();
    6. }
    7. }
    8.  
    9. void clsCadClientes::on_cmdSearch_clicked()
    10. {
    11. while (ui->txtEdit->find(ui->lineEdit->text()))
    12. {
    13. ui->txtEdit->setTextBackgroundColor("yellow");
    14. }
    To copy to clipboard, switch view to plain text mode 
    How do I post the source code?

    marcos.miranda
    msn: jmbm.trab@bol.com.br
    Attached Files Attached Files
    Last edited by wysota; 11th June 2012 at 07:51. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Thread Search in text file large

    And what do you want us to do with what you posted?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Thread Search in text file large

    Quote Originally Posted by marcos.miranda View Post
    First explain to me how do I post to blocks of text like you did.
    You place [code] and [/code] tags around your code.

    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.

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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:

    Qt Code:
    1. QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
    2. tr("Text Files (*.txt);;MSWord Files (*.doc)"));
    3. if (fileName != "") {
    4. QFile file(fileName);
    5. if (!file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
    6. QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
    7. return;
    8. }
    9.  
    10. QTextStream in(&file);
    11. ui->txtEdit->setPlainText(in.readAll());
    12. 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:

    Qt Code:
    1. int vnumLinhaInit,vnumLinhasTotal;
    2.  
    3. vnumLinhaInit=0;
    4. vnumLinhasTotal = ui->txtEdit->document()->lineCount();
    5. ui->txtEdit->moveCursor(QTextCursor::Start);
    6.  
    7. while (ui->txtEdit->find(ui->lineEdit->text()))
    8. {
    9. ui->txtEdit->setTextBackgroundColor("yellow");
    10. ui->lblContador->setText(QString::number( vnumLinhaInit ));
    11. vnumLinhaInit += 1;
    12. }
    13.  
    14. QMessageBox msgBox;
    15. msgBox.setText("A Busca Terminou !!!");
    16. 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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Thread Search in text file large

    Quote Originally Posted by marcos.miranda View Post
    When I press the Open File button and select the text file into a string search the system freezes.
    The system or your program?


    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.

    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().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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....

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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....

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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..

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Advice: Reading large text file.
    By enricong in forum Qt Programming
    Replies: 7
    Last Post: 16th July 2011, 12:11
  2. Search HTML in non-gui thread
    By mirag in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 13:38
  3. Replies: 4
    Last Post: 25th May 2008, 20:01
  4. Text search utility
    By NewGuy in forum Newbie
    Replies: 7
    Last Post: 23rd July 2006, 11:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.