Results 1 to 9 of 9

Thread: displaying Text in QTAble dynamically

  1. #1
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default displaying Text in QTAble dynamically

    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???????????

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: displaying Text in QTAble dynamically

    What values do you pass to QTable::setText()?

  3. #3
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: displaying Text in QTAble dynamically

    well i pass QString as setText() only take QString as the argument

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: displaying Text in QTAble dynamically

    Would you mind showing the relevant piece of code, where you read a file and fill the table?
    J-P Nurmi

  5. #5
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: displaying Text in QTAble dynamically

    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;
    }

    }

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: displaying Text in QTAble dynamically

    Quote Originally Posted by raghvendramisra View Post
    Qt Code:
    1. table1->setText(1,1,szTmp);
    To copy to clipboard, switch view to plain text mode 
    This sets text to same cell (1,1) every time. You might also want to consider using QFile for more convenient file handling..
    J-P Nurmi

  7. #7
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: displaying Text in QTAble dynamically

    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???????

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: displaying Text in QTAble dynamically

    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?).
    J-P Nurmi

  9. #9
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: displaying Text in QTAble dynamically

    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

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.