Results 1 to 10 of 10

Thread: Update a row

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Update a row

    Hello anyone,

    In a QTableWidget you can update a item.
    But is it possible to update a row when you click on the row in QTable through a QDialog.
    I want to see the items in a row in the QLineEdits in QDialog.

    Qt Code:
    1. void ContactWindow::edit(QTableWidgetItem *item )
    2. {
    3. int row;
    4. contactTable->selectRow(row);
    5.  
    6. {
    7. contactDialog dlg(this);
    8. dlg.leBedrijf->setText(item->text());
    9. dlg.leContact->setText(item->text());
    10. dlg.leTel->setText(item->text());
    11. if(dlg.exec() == QDialog::Accepted) {
    12. }
    13.  
    14. return;
    15. }
    16. }
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    There must be some changes in the code it only display one item.

  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: Update a row

    Shouldn't there be something like this for every column?
    Qt Code:
    1. QTableWidget *item = contactTable->item( row, 0 );
    2. QString text;
    3. if( item != 0 ) {
    4. text = item->text();
    5. }
    6. dlg.leContact->setText( text );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update a row

    Qt Code:
    1. QTableWidget *item = contactTable->item( row, 0 );
    2. QString text;
    3. if( item != 0 ) {
    4. text = item->text();
    5. }
    6. dlg.leContact->setText( text );
    To copy to clipboard, switch view to plain text mode 

    I have tried is pieces off code in my edit function but it gives a error text() is no member off Class QTableWidget.

    I have change the code because off the error.
    Qt Code:
    1. void ContactWindow::edit(QTableWidgetItem *item )
    2. {
    3. int row;
    4. contactTable->selectRow(row);
    5.  
    6. contactTable->item( row, 0 );
    7. QString bedrijf;
    8. if( item != 0 ) {
    9. bedrijf = item->text();
    10. }
    11. contactTable->item( row, 1 );
    12. QString contact;
    13. if( item != 0 ) {
    14. contact = item->text();
    15. }
    16. contactTable->item( row, 2 );
    17. QString tel;
    18. if( item != 0 ) {
    19. tel = item->text();
    20. }
    21.  
    22. {
    23. contactDialog dlg(this);
    24. dlg.leBedrijf->setText( bedrijf);
    25. dlg.leContact->setText( contact );
    26. dlg.leTel->setText( tel );
    27. if(dlg.exec() == QDialog::Accepted) {
    28. }
    29.  
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    It still not working when i click on the row in contactTable i see in the Dialog in the lineEdits the same items from the first column.

    Example off my Dialog LineEdits:

    Bedrijf: TMC
    Contact: TMC
    Tel: TMC

  4. #4
    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: Update a row

    Quote Originally Posted by dragon
    I have tried is pieces off code in my edit function but it gives a error text() is no member off Class QTableWidget.
    It should be QTableWidgetItem instead of QTableWidget.

    Quote Originally Posted by dragon
    I have change the code because off the error.
    [...]
    It still not working when i click on the row in contactTable i see in the Dialog in the lineEdits the same items from the first column.
    Because you always retrieve data from the same item.

  5. #5
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update a row

    I have change the QTableWidget into QTableWidgetItem.
    In my Dialog it display nothing in LineEdits.
    Qt Code:
    1. void ContactWindow::edit(QTableWidgetItem* )
    2. {
    3. int row;
    4. contactTable->selectRow(row);
    5.  
    6. QTableWidgetItem *item = contactTable->item( row, 0 );
    7. QString bedrijf;
    8. if( item != 0 ) {
    9. bedrijf = item->text();
    10. }
    11. QTableWidgetItem *contactitem = contactTable->item( row, 1 );
    12. QString contact;
    13. if( contactitem != 0 ) {
    14. contact = contactitem->text();
    15. }
    16. QTableWidgetItem *telitem = contactTable->item( row, 2 );
    17. QString tel;
    18. if( telitem != 0 ) {
    19. tel = telitem->text();
    20. }
    21.  
    22. {
    23. contactDialog dlg(this);
    24. dlg.leBedrijf->setText( bedrijf);
    25. dlg.leContact->setText( contact );
    26. dlg.leTel->setText( tel );
    27. if(dlg.exec() == QDialog::Accepted) {
    28. }
    29.  
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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: Update a row

    Quote Originally Posted by dragon
    I have change the QTableWidget into QTableWidgetItem.
    In my Dialog it display nothing in LineEdits.
    You didn't initialize the row variable.

  7. #7
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update a row

    What do you mean with didn't initialize the row variable.
    I have initialize the row varible in the begin of the function.

    Qt Code:
    1. int row; // You mean this ?
    2. contactTable->selectRow(row);
    3.  
    4. QTableWidgetItem *item = contactTable->item( row, 0 );
    5. QString bedrijf;
    6. if( item != 0 ) {
    7. bedrijf = item->text();
    8. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    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: Update a row

    Quote Originally Posted by dragon
    int row; // You mean this ?
    Yes, it has some random value now. You have to set it to the current row number.

  9. #9
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Update a row

    Quote Originally Posted by dragon
    I have initialize the row varible in the begin of the function.
    Writing something like
    Qt Code:
    1. int foo;
    To copy to clipboard, switch view to plain text mode 
    is declaring a variable, that is you are saving memory space for that variable but the memory has something in it that you don't know and depends on what used that memory space before. Initializing a variable is assigning a value to it when you declare it like
    Qt Code:
    1. int foo=0;
    To copy to clipboard, switch view to plain text mode 
    and now you are certain that foo==0 and not foo==whatever happens to be in the memory I just allocated

  10. #10
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update a row

    Thanks jacek and yop for your answer and time.
    The problem is solved.
    I did only a last modifaction on the first line in my function..
    If i did:
    int row = 0; with the combination selectRow(row) the Dialog shows only the first row.
    Here the replacement off the code;
    Qt Code:
    1. int row = contactTable->currentRow();
    To copy to clipboard, switch view to plain text mode 

    Thanks and Bye.

Similar Threads

  1. Is Update() the right way?
    By td in forum Newbie
    Replies: 1
    Last Post: 5th December 2008, 15:54
  2. Qt Update project - Opinions wanted
    By pvdk in forum Qt Programming
    Replies: 0
    Last Post: 8th November 2008, 09:41
  3. update() works fine sometime but not everytime..!!
    By salmanmanekia in forum Qt Programming
    Replies: 19
    Last Post: 22nd August 2008, 10:11
  4. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 10:42
  5. immediate update of QT object
    By db in forum Newbie
    Replies: 3
    Last Post: 14th August 2007, 13:25

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.