Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6970243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:41:06+00:00 2026-05-27T16:41:06+00:00

I am Trying to read data from text files and save tokens in SQLite

  • 0

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

QDir dir(ui->lineEdit->text());
if(dir.exists() && ui->lineEdit->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 < list.size(); ++i)  {
        QFileInfo fileInfo = list.at(i);
        QFile file(ui->lineEdit->text()+"/"+ fileInfo.fileName());

        if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
            QSqlQuery qrry;
            qrry.prepare( "INSERT INTO documents (path) VALUES ('"+ui->lineEdit->text()+"/"+ fileInfo.fileName()+"')" );
            qrry.exec();

            QString line;
            QTextStream in(&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<line_tokens.length();i++){
                    if(line_tokens[i].length()>3){
                        QSqlQuery qry;
                        qry.prepare( "INSERT INTO tokens (token,path,line) VALUES ('"+line_tokens[i]+"', '"+ui->lineEdit->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 << std::endl;
    }
}
else{
    QMessageBox::critical(this,"Directory choosen is Not Valid","Please Make Sure That You Have Choosen A Valid Directory!");
}

it works for a small file sizes but when it comes to huge amount of data it becomes gives the “not responding” message

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:41:07+00:00Added an answer on May 27, 2026 at 4:41 pm

    First, you can simply… wait until it process all the data. If you should run this program only once, it is ok.

    Then, you should not generate such stream of requests to database. It is much better to run one single big insertion, than a lot of small. You can use batch execution.

    Then, it’s probably no reason of trying to parallel writing to Db. I think, it’s smart enough to manage writing efficiently.

    But it worth paralleling parsing. The best solution here is to use QtConcurrent framework. It is made exactly for such tasks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read data from excel files using datatable. The command select
I'm trying to read data from a text file and assign it to arrays.
I have an application that imports data read from text files from a directory
I am trying to read in data from a text file using numpy.loadtxt with
I'm trying to read data from a text file, clear it, and then write
I'm trying to read data from a.csv file to ouput it on a webpage
I'm trying to read data from SQL Server database using Perl and the DBI
I am trying to read data from an RS-232 port. Does anyone have an
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I am trying to read data from a bluetooth barcode scanner (KDC300) using C.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.