Results 1 to 3 of 3

Thread: help on QList<QTableWidgetItem*>

  1. #1
    Join Date
    Oct 2008
    Location
    Dar es Salaam,Tanzania
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default help on QList<QTableWidgetItem*>

    how do iterate over QList retrieve the values then display them on a dialog for editing?
    here is my function

    Qt Code:
    1. void AddressBook::editItem()
    2. {
    3.  
    4. if( !tableWidget->currentItem())
    5. return;
    6. else
    7. QList<QTableWidgetItem*> selected = tableWidget->selectedItems();
    8. for (QList<QTableWidgetItem *>::iterator it=selected.begin();it!=selected.end();it++)
    9. {
    10. QString item[i] = (*it);
    11. }
    12.  
    13. editDialog dlg;
    14. dlg.setId(item[0]);
    15. dlg.setname(item[1]);
    16. dlg.setemail(item[2]);
    17. dlg.setphone(item[3]);
    18. dlg.setgrossSalary(item[4]);
    19.  
    20.  
    21. if( dlg.exec() == QDialog::Accepted )
    22. {
    23. double HRA = dlg.grossSalary().toDouble() * 0.2;
    24. double transport = dlg.grossSalary().toDouble() * 0.1;
    25. double medical = 200.0;
    26.  
    27. item[0] = dlg.id();
    28. item[1] = dlg.name();
    29. item[2] = dlg.email();
    30. item[3] = dlg.phone();
    31. item[4] = dlg.grossSalary();
    32.  
    33. item[5] .setNum( item[4].toDouble() - HRA - transport - medical,'f',2 ); //netsalary
    34.  
    35. item[6].setNum(item[5].toDouble() * 12,'f',4);
    36. ++row;
    37. for(int col = 0; col < 7 ; col++)
    38. {
    39.  
    40. QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(item[col]));
    41.  
    42. newItem->setTextAlignment(Qt::AlignCenter);
    43.  
    44. tableWidget->setItem(row, col, newItem);
    45. }
    46. }
    47.  
    48. }
    To copy to clipboard, switch view to plain text mode 

    when i compiled the program i got this error!


    Running build steps for project myaddressbook...
    Configuration unchanged, skipping QMake step.
    Starting: /usr/bin/make debug -w
    make: Entering directory `/home/roncriss/development/myaddressbook'
    /usr/bin/make -f Makefile.Debug
    make[1]: Entering directory `/home/roncriss/development/myaddressbook'
    g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtNetwork -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -Idebug -I. -o debug/addressbook.o addressbook.cpp
    addressbook.cpp: In member function ‘void AddressBook::editItem()’:
    addressbook.cpp:115: error: ‘selected’ was not declared in this scope
    addressbook.cpp:117: error: variable-sized object ‘item’ may not be initialized
    addressbook.cpp:117: warning: unused variable ‘item’
    addressbook.cpp:121: error: ‘item’ was not declared in this scope
    make[1]: Leaving directory `/home/roncriss/development/myaddressbook'
    make: Leaving directory `/home/roncriss/development/myaddressbook'
    make[1]: *** [debug/addressbook.o] Error 1
    make: *** [debug] Error 2
    Exited with code 2.
    Error while building project myaddressbook
    When executing build step 'Make'

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: help on QList<QTableWidgetItem*>

    did you include
    #include <QList>
    ?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: help on QList<QTableWidgetItem*>

    2 roncriss: This problem occur because you forgot about {} for else. Your code should be like that:

    Qt Code:
    1. if( !tableWidget->currentItem())
    2. return;
    3. else {
    4. QList<QTableWidgetItem*> selected = tableWidget->selectedItems();
    5.  
    6. ....
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QList<A*> indexOf
    By Moppel in forum General Programming
    Replies: 6
    Last Post: 8th August 2017, 14:17
  2. QList<char*> dies
    By thomaspu in forum Qt Programming
    Replies: 11
    Last Post: 15th March 2008, 22:47
  3. QList<myObject*> myObjectList count() error
    By morty in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2006, 15:08

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.