PDA

View Full Version : Load text file to tableview



Andree
24th November 2014, 13:32
Hello everyone,

I have a problem with loading the data from the file into the control tableview. For now, I created a function that has to load data from a file.


void example::load(const QString &file)
{
QString p(":/folder/file/");


p+=file;
QFile filein(p);
if (!filein.open(QFile::ReadOnly))
qDebug(Error couldn't open file: %s",qPrintable(file));
double p1;

QTextStream stream(&filein);
while (!filein.atEnd())
{
stream>>p1;

}
stream.readLine() ;
}

Tableview indicator added to the form, and now i want the data to be loaded when you start the application.

anda_skoa
24th November 2014, 13:35
Easiest way is to populate a QStandardItemModel with your data and then set this as the model on the view.

Cheers,
_

Andree
24th November 2014, 14:23
You can give an example of such a table?

anda_skoa
24th November 2014, 16:48
The documentation for QStandardItemModel has one.

Cheers,
_