Results 1 to 3 of 3

Thread: Getting an item from an empty table widget

  1. #1
    Join Date
    Jul 2009
    Location
    São Paulo - Brasil
    Posts
    20
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting an item from an empty table widget

    Hi, everybody, its my first time here.

    I have a little problem, I am a beginner in qt, but I liking it. Well, to the problem:

    Qt Code:
    1. QString helper;
    2. item1 = ui.mywidget_table->item(0,1);
    3. helper = item1->text();
    To copy to clipboard, switch view to plain text mode 

    I´ve received a error in the last line because my cell is empty, but I think that I need to test if the cell is empty, how can I make that?

    Thx in advance.

    Jorge.

  2. #2
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Getting an item from an empty table widget

    Hi ProTonS!

    if there is no item on the location specified, the item function will return 0.
    Just test the return value to see if it's a valid item or not.
    Qt Code:
    1. QString helper;
    2. item1 = ui.mywidget_table->item(0,1);
    3. if(item1!=0)
    4. {
    5. helper = item1->text();
    6. }
    To copy to clipboard, switch view to plain text mode 
    or check that the item exist before calling the item function.
    Qt Code:
    1. QString helper;
    2. if( ui.mywidget_table->rowCount() > 0 && ui.mywidget_table->columnCount() > 1)
    3. {
    4. item1 = ui.mywidget_table->item(0,1);
    5. helper = item1->text();
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2009
    Location
    São Paulo - Brasil
    Posts
    20
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting an item from an empty table widget

    Thanks for your help, gsmiko.

    I´m going to test it.

    Bye Bye.

Similar Threads

  1. Replies: 0
    Last Post: 8th July 2009, 11:01
  2. Find item in table
    By JohnToddSr in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2009, 16:24
  3. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  4. Table Widget Vs. Table View
    By winston2020 in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2008, 09:56
  5. Replies: 4
    Last Post: 4th February 2008, 06:16

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.