Note that there are some explanatory texts on larger screens.

plurals
  1. POQt Multi-Threading
    text
    copied!<p>I am Trying to read data from text files and save tokens in SQLite databae running on windows The Files size is about 300MB , the thing is that I am not using threads yet , the application collapses and stuck with "not responding" message here is my code</p> <pre><code>QDir dir(ui-&gt;lineEdit-&gt;text()); if(dir.exists() &amp;&amp; ui-&gt;lineEdit-&gt;text()!=""){ CreateTables(); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setSorting(QDir::Size | QDir::Reversed); QFileInfoList list = dir.entryInfoList(); for (int i = 0; i &lt; list.size(); ++i) { QFileInfo fileInfo = list.at(i); QFile file(ui-&gt;lineEdit-&gt;text()+"/"+ fileInfo.fileName()); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QSqlQuery qrry; qrry.prepare( "INSERT INTO documents (path) VALUES ('"+ui-&gt;lineEdit-&gt;text()+"/"+ fileInfo.fileName()+"')" ); qrry.exec(); QString line; QTextStream in(&amp;file); int lineCount=0; while (!in.atEnd()) { line = in.readLine(); lineCount++; QRegExp rx("(\\ |\\,|\\.|\\:|\\t)"); QStringList line_tokens = line.split(rx); for(int i=0;i&lt;line_tokens.length();i++){ if(line_tokens[i].length()&gt;3){ QSqlQuery qry; qry.prepare( "INSERT INTO tokens (token,path,line) VALUES ('"+line_tokens[i]+"', '"+ui-&gt;lineEdit-&gt;text()+"/"+ fileInfo.fileName()+"','"+QString::number(lineCount)+"')" ); qry.exec(); } } } } else{ QMessageBox::information(this,"File Read Error","Couldn't Open File, Please Make Sure That This File Is Accessable And Readable !"); } std::cout &lt;&lt; std::endl; } } else{ QMessageBox::critical(this,"Directory choosen is Not Valid","Please Make Sure That You Have Choosen A Valid Directory!"); } </code></pre> <p>it works for a small file sizes but when it comes to huge amount of data it becomes gives the "not responding" message</p> <p>will threads save the application from being collapsed ?? and how may I implements threads to do this job for more thant 20 files of 15 MB each</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload