Results 1 to 4 of 4

Thread: Item In QTableWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Location
    Chennai , India
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Item In QTableWidget

    how can i check the item in the Qtablewidget having value or not

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Item In QTableWidget

    QVariant QTableWidgetItem::data ( int role ) const [virtual]

    Returns the item's data for the given role.

    QString QTableWidgetItem::text () const

    Returns the item's text.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    Join Date
    Jul 2012
    Location
    Chennai , India
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Item In QTableWidget

    for (int row=0 ; row < ui->widget->rowCount();row++)
    {
    qDebug()<<"Ckeck point X "<<row;
    QTableWidgetItem *item_test = ui->widget->item(row, 0);
    if(!item_test->text().isEmpty())
    {
    check_count++;
    qDebug()<<"Checkpoint y "<<row;
    }
    c++;
    }
    qDebug()<<"Check Count"<<check_count;

    for first loop(row=0) its working but in the next loop(row=1) it displays Ckeck point X 1;then the program is terminated
    pls help me to fix this problem

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Item In QTableWidget

    Having a row in the QTableWidget does not mean that all the columns on the row will have items on them. Items (QTableWidgetItem) have to be explicitly set on the cell(row, column)


    Qt Code:
    1. for(int row = 0; row < ui->widget->rowCount(); row++)
    2. {
    3. qDebug() << "Ckeck point X " << row;
    4. QTableWidgetItem *item_test = ui->widget->item(row, 0);
    5. if(item_test != 0) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    6. {
    7. if(!item_test->text().isEmpty())
    8. {
    9. check_count++;
    10. qDebug() << "Checkpoint y " << row;
    11. }
    12. }
    13. else
    14. {
    15. qDebug() << "Checkpoint z: Item not set " << row; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    16. }
    17. c++;
    18. }
    19. qDebug() << "Check Count" << check_count;
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. QTableWidget NW corner header item?
    By McKee in forum Qt Programming
    Replies: 9
    Last Post: 30th May 2012, 23:44
  2. [SOLVED] QTableWidget can not add item correctly
    By porterneon in forum Newbie
    Replies: 0
    Last Post: 1st August 2011, 17:49
  3. Item edit in QTableWidget
    By manmohan in forum Newbie
    Replies: 3
    Last Post: 29th April 2011, 16:56
  4. QTableWidget::item to Double?
    By Afflicted.d2 in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2006, 06:23
  5. QTableWidget item checkable and combo?
    By darpan in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2006, 07:12

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
  •  
Qt is a trademark of The Qt Company.