PDA

View Full Version : Application crashes if no there selected row on a qtablewidget



marcelrc
27th May 2006, 12:29
QVariant row = ui...._tableWidget->currentRow();
if (row.toBool()) {
atual_row = row.toInt();
...

or


if (ui...._tableWidget->currentRow()) {
...

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.

wysota
27th May 2006, 12:38
"current" and "selected" is not the same. You are not checking the selection here.

marcelrc
27th May 2006, 12:57
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.

wysota
27th May 2006, 13:17
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.

marcelrc
27th May 2006, 13:34
:D
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?

wysota
27th May 2006, 13:44
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).