QTable - Data Base Problem
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
Re: QTable - Data Base Problem
Quote:
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?
Re: QTable - Data Base Problem
Re: QTable - Data Base Problem
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.
Re: QTable - Data Base Problem
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!
Re: QTable - Data Base Problem
Quote:
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:
Code:
QFile file( "file.txt" );
if ( file.open( IO_ReadOnly ) ) {
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();
}
Re: QTable - Data Base Problem
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.
Re: QTable - Data Base Problem
Why don't you ask the model, using itemData?
Re: QTable - Data Base Problem
Oh, are you using Qt3?
Then use QTable::text(int row, int col ).
Should work fine.
Regards
Re: QTable - Data Base Problem