PDA

View Full Version : displaying Text in QTAble dynamically



raghvendramisra
29th August 2007, 07:40
hi,
i have an application in which i have to read the file and display the data in a table.
I am using setText() function to display the text.

now my problem is that the text is displayed in the table only after file has reached the end i.e i am getting only the last data in the table.
but i want to view data dynamically i.e the table cell should show all the data read from the file.

how can i do this???????????

jacek
29th August 2007, 20:38
What values do you pass to QTable::setText()?

raghvendramisra
30th August 2007, 04:32
well i pass QString as setText() only take QString as the argument

jpn
30th August 2007, 08:23
Would you mind showing the relevant piece of code, where you read a file and fill the table?

raghvendramisra
30th August 2007, 11:08
ya! the code below is from the section where i am reading the binary file and displaying it in the table cell.
but i am able to see only the last msg.

///////////////////////

unsigned int uiData;
QString szTmp;

fp = fopen("test.bin","r+b"); //test.bin is the binary file containing data in the form of structure MNTPACK
fseek( fp, 0L, SEEK_SET);


while(1)
{

fread(pMtStruct,sizeof(MNTPACK), 1, fp); //pMtStruct is a pointer to MNTPACK struct

if(!feof(fp))
{

uiData=pMtStruct->DataPack; //DataPack is an unsigned integer Value

szTmp = szTmp.setNum(uiData,16);
table1->setText(1,1,szTmp);
table1->updateCell(1,1);
}
else
{

break;
}

}

jpn
30th August 2007, 13:02
table1->setText(1,1,szTmp);


This sets text to same cell (1,1) every time. You might also want to consider using QFile for more convenient file handling.. ;)

raghvendramisra
31st August 2007, 04:25
actually thats what the problem is!!!!!!!!!!!!!
I wanted to write the data in the same cell and view it as it changes.
but instead i am able to view only the last data from the file.
hope you got the problem???????:(

jpn
31st August 2007, 09:27
First of all, you would have to let the application to process its events every once in a while to let it actually receive necessary paint events and so on. You could try calling qApp->processEvents() after each setText() to make it happen. However, that might still be a bit too fast for one actually to see the changes, so you might have to change the approach a bit (delayed changes?).

raghvendramisra
31st August 2007, 11:47
Thanx ,
i tried this by using thread and it is working well :)

But now the problem is that in QTable i am displaying the contents read from file as QString. Now if i read a pure numerical value , it is displayed at the right End of the cell but a string is displayed at the left End of the cell. so this looks very auckward.

How can i display the contents at one location only in a cell

Thanks