Hello friends,
I try a little routine to fill up a tableview from a textfile.
//**************************************************************************
void Window
::openFileInTable(const QModelIndex & index
) //**************************************************************************
{
int digits[6];
int iSegCount(0);
int iCopyFLines(0);
if ( index.isValid())
{
selectedFile = model->filePath( index );
bodyEdit->clear();
bodyEdit->append(selectedFile);
QFile file(selectedFile
);
return;
int fileLines(1);
while (!InputDataFile.atEnd()) {
InputDataFile.readLine();
fileLines++;
}
file.close();
return;
tableModel->setRowCount(0) ;
int Max_Number_of_Columns(36);
int Max_Number_of_Lines(0);
tableModel->setColumnCount(Max_Number_of_Columns + 3) ;
progressDialog->setMaximum(fileLines);
for(iSegCount=0;iSegCount<6;iSegCount++){digits[iSegCount]=0;}
while (!InputDataFile.atEnd())
{
buf = InputDataFile.readLine();
buffer_list = buf.split(Delimiter);
for (int column = 0; column <= Max_Number_of_Columns; column ++)
{
tableModel->setItem(Max_Number_of_Lines, column, item) ;
}
Max_Number_of_Lines++;
progressDialog->setLabelText(tr("Transfer %1...").arg(selectedFile));
progressDialog->setWindowModality(Qt::WindowModal);
progressDialog->setValue(Max_Number_of_Lines);
}
iCopyFLines=Max_Number_of_Lines;
iSegCount = 0;
do {
digits[iSegCount++] = iCopyFLines % 10;
} while ((iCopyFLines /= 10) > 0);
progressCountEiner->setNumber(digits[0]);
progressCountZehner->setNumber(digits[1]);
progressCountHunderter->setNumber(digits[2]);
progressCountTausender->setNumber(digits[3]);
progressCountZehnTausender->setNumber(digits[4]);
progressCountHundertTausender->setNumber(digits[5]);
progressDialog->setValue(fileLines);
trackView->setAutoFillBackground(true);
trackView->setAlternatingRowColors(true);
trackView->resizeColumnsToContents();
trackView->setModel(tableModel);
trackView->show() ;
}
}
//**************************************************************************
void Window::openFileInTable(const QModelIndex & index )
//**************************************************************************
{
int digits[6];
int iSegCount(0);
int iCopyFLines(0);
QString selectedFile;
if ( index.isValid())
{
selectedFile = model->filePath( index );
selectedFile.replace(QString("/"),QString("\\"));
bodyEdit->clear();
bodyEdit->append(selectedFile);
QFile file(selectedFile);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
int fileLines(1);
QTextStream InputDataFile(&file);
while (!InputDataFile.atEnd()) {
InputDataFile.readLine();
fileLines++;
}
file.close();
QTextStream InputDataFile(&file);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QStringList buffer_list;
QString Delimiter(";");
tableModel = new QStandardItemModel;
tableModel->setRowCount(0) ;
int Max_Number_of_Columns(36);
int Max_Number_of_Lines(0);
tableModel->setColumnCount(Max_Number_of_Columns + 3) ;
progressDialog->setMaximum(fileLines);
for(iSegCount=0;iSegCount<6;iSegCount++){digits[iSegCount]=0;}
QString buf;
while (!InputDataFile.atEnd())
{
buf = InputDataFile.readLine();
buffer_list = buf.split(Delimiter);
for (int column = 0; column <= Max_Number_of_Columns; column ++)
{
QStandardItem * item = new QStandardItem(buffer_list[column]);
tableModel->setItem(Max_Number_of_Lines, column, item) ;
}
Max_Number_of_Lines++;
progressDialog->setLabelText(tr("Transfer %1...").arg(selectedFile));
progressDialog->setWindowModality(Qt::WindowModal);
progressDialog->setValue(Max_Number_of_Lines);
}
iCopyFLines=Max_Number_of_Lines;
iSegCount = 0;
do {
digits[iSegCount++] = iCopyFLines % 10;
} while ((iCopyFLines /= 10) > 0);
progressCountEiner->setNumber(digits[0]);
progressCountZehner->setNumber(digits[1]);
progressCountHunderter->setNumber(digits[2]);
progressCountTausender->setNumber(digits[3]);
progressCountZehnTausender->setNumber(digits[4]);
progressCountHundertTausender->setNumber(digits[5]);
progressDialog->setValue(fileLines);
trackView->setAutoFillBackground(true);
trackView->setAlternatingRowColors(true);
trackView->resizeColumnsToContents();
trackView->setModel(tableModel);
trackView->show() ;
}
}
To copy to clipboard, switch view to plain text mode
What I detect is that the bigger the textfile is the greater the memory consumption is.
The problem I think is the for loop:
for (int column = 0; column <= Max_Number_of_Columns; column ++)
{
tableModel->setItem(Max_Number_of_Lines, column, item) ;
}
for (int column = 0; column <= Max_Number_of_Columns; column ++)
{
QStandardItem * item = new QStandardItem(buffer_list[column]);
tableModel->setItem(Max_Number_of_Lines, column, item) ;
}
To copy to clipboard, switch view to plain text mode
Have somebody a tip to filling up my tableview with better performance or lower memory consumption ..???
Bookmarks