Results 1 to 6 of 6

Thread: Application crashes if no there selected row on a qtablewidget

  1. #1
    Join Date
    May 2006
    Location
    Brasil
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Application crashes if no there selected row on a qtablewidget

    Qt Code:
    1. QVariant row = ui...._tableWidget->currentRow();
    2. if (row.toBool()) {
    3. atual_row = row.toInt();
    4. ...
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. if (ui...._tableWidget->currentRow()) {
    2. ...
    To copy to clipboard, switch view to plain text mode 

    It´s crasshing my application if no row is selected on qtablewidget. The copilation is ok.

    Alternativily, how to known if some row is selected or no on qtablewidget?

    I use Qt 4.1.3, MingW, Windows XP.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application crashes if no there selected row on a qtablewidget

    "current" and "selected" is not the same. You are not checking the selection here.

  3. #3
    Join Date
    May 2006
    Location
    Brasil
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Application crashes if no there selected row on a qtablewidget

    If I select a item on qtablewidget, the currentRow() function returns the number of row selected, or of the current row? Or not?

    I just want to know if some row or item is selected on table. The solution in my code is crasshing on execution. The code is in a custom slot function connected with a pushbutton. When I click the button, if no item or row of the table is selected, crashes, if there selection, works ok.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application crashes if no there selected row on a qtablewidget

    Quote Originally Posted by marcelrc
    If I select a item on qtablewidget, the currentRow() function returns the number of row selected, or of the current row? Or not?
    "Current" item is the one which has the keyboard focus (thus there is always a "current row" if the widget has focus). "Selected" item is an item, which is highlighted by a changed background in most widget styles. There can be many selected items but only one current item.

    I just want to know if some row or item is selected on table. The solution in my code is crasshing on execution. The code is in a custom slot function connected with a pushbutton. When I click the button, if no item or row of the table is selected, crashes, if there selection, works ok.
    Use QTableWidget::selectedItems() to retrieve a list of selected items. If the list is empty, no items are selected.

  5. The following user says thank you to wysota for this useful post:

    marcelrc (27th May 2006)

  6. #5
    Join Date
    May 2006
    Location
    Brasil
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Application crashes if no there selected row on a qtablewidget


    Thak you very much wysota! It's solved my problem!
    You are fast to response.
    I think you was hired by somebody only to response this forum. Is this your job?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Application crashes if no there selected row on a qtablewidget

    Quote Originally Posted by marcelrc
    I think you was hired by somebody only to response this forum. Is this your job?
    No, I do it in my free time (although I don't have much time free now).

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2006, 18:51

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.