Results 1 to 12 of 12

Thread: Thread Search in text file large

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  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

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


  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, wysota

    Is it possible when I call a new form of search it opens in a separate Thread ?
    How?



    Thanks....

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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.


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

    The QFile can open a file type. "Rtf and. Doc"?
    How would the code if you can?


    Thanks..

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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
  •  
Qt is a trademark of The Qt Company.