Results 1 to 3 of 3

Thread: Copying row from one table to another

  1. #1
    Join Date
    Jan 2006
    Location
    Ukraine
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Copying row from one table to another

    Hi, All!
    I think I need some advice... I want to copy row from one QTableWidget to another. The first idea was to copy cell-by-cell, something like this:

    Qt Code:
    1. QTableWidgetItem Table2Item[Table1->columnCount()];
    2. for(j=0;j<(Table1->columnCount());j++)
    3. {
    4. Table2Item[j] = *Table1->item(Table1->currentRow(),j);
    5. Table2->setItem(Table2->currentRow(),j,&Table2Item[j]);
    6. }
    To copy to clipboard, switch view to plain text mode 

    But this just inserts an empty row into Table2... I think I made a stupid mistake, but I do not see where... Maybe there is another way to copy the row?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Copying row from one table to another

    Hint: use the copy constructor of QTableWidgetItem and copy the item directly, not cell by cell.

    Your solution doesn't work because you're trying to add an item that is owned by the other table.

    Regards

  3. The following user says thank you to marcel for this useful post:

    ser_bur (29th May 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Ukraine
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Copying row from one table to another

    YESS!! It works. Why right solution never comes itself?
    Thanks!

Similar Threads

  1. Easiest way to display icons in a table
    By ghorwin in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2007, 13:09
  2. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  3. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50
  4. Adding row in a Table after selected row
    By ankurjain in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2006, 18:06
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 11:03

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.