PDA

View Full Version : QTable - Data Base Problem



esq
23rd May 2007, 00:29
Hello,
I need little help. I am writeing a small library data base using QT Designer. And I got a problem. I don't know how to load data from file to QTable object that I've got on my form. Example file:
cell_01;cell_02;cell_03;cell_04
cell_05;cell_06;cell_07;cell_08
cel1_09;cell_l0;cell_11;cell_12
cell_13;cell_14;cell_l5;cell_l6
etc...
And I want to load this into my QTable object so that will look like that:
http://img255.imageshack.us/img255/2291/qtra9.jpg

Please, help me.
esq

high_flyer
23rd May 2007, 09:26
I don't know how to load data from file to QTable
Is this a data base file or just a "normal" text/binary file?
If its a database, which one is it?

esq
23rd May 2007, 12:44
this is normal text file

high_flyer
23rd May 2007, 13:01
Look up QFile and QTextStream in the docs to see how you can read the file.
If you still have specific questions, post them here.

esq
23rd May 2007, 21:40
Ok, thanks for that.
I'm new at QT and kind lost in this at the time.
I wrote a function and it is inserting values into specific cells using lineEdit fields. It looks like this:
void Form1::wpiszWart()
{
int row = table4->numRows();
table4->insertRows(row);
table4->setText(row, 0, lineEdit1->text());
table4->setText(row, 1, lineEdit2->text());
table4->setText(row, 2, lineEdit3->text());
table4->setText(row, 3, lineEdit4->text());
}
Could You help me write some little code example how to save cell vaule into file and then how to open the file and insert that value into specific cell?
Thanks in advance!

high_flyer
24th May 2007, 09:28
Could You help me write some little code example how to save cell vaule into file and then how to open the file and insert that value into specific cell?
Well, I could.
But at the same tocken you could just read the docs, which already supply all the examples you need! ;)
From the docs:


QStringList lines;
QFile file( "file.txt" );
if ( file.open( IO_ReadOnly ) ) {
QTextStream stream( &file );
QString line;
int i = 1;
while ( !stream.atEnd() ) {
line = stream.readLine(); // line of text excluding '\n'
printf( "%3d: %s\n", i++, line.latin1() );
lines += line;
}
file.close();
}

esq
27th May 2007, 21:22
thanks for that!

I've got another question. How to get value from specific cell from QTable and insert it into lineEdit field? I know how to get value from lineEdit and insert it into specific cell, but i've got problems with the opposite situation.

marcel
27th May 2007, 21:50
Why don't you ask the model, using itemData?

marcel
27th May 2007, 21:52
Oh, are you using Qt3?
Then use QTable::text(int row, int col ).
Should work fine.

Regards

esq
27th May 2007, 23:08
thanks! it works fine