retrieve text inside QLineEdit inside QTableWidget
-
Hi, im trying to get the data displayed in a QTableWidget, everything comes from a database and some calculations to the data itself, everytime i want to retrieve the data from a cell using the follow code, my program wont compile with the follow error error: use of deleted function 'QLineEdit::QLineEdit(const QLineEdit&) the table was made with Qt Designer
QLineEdit a = widget_PP.Registros_General->cellWidget(1,1)->findChild<QLineEdit>();
as far as i know the cellwidget retrieves the data inside the qwidget, i also used a qobject_cast but i got a similar error
QLineEdit a = qobject_cast<QLineEdit>(widget_PP.Registros_General->cellWidget(0,0));
i need the information display on the QTableWidget so i can send it to my printer, any idea where i might be wrong? i did try using item(), but that wont work because im using a QlineEdit
-
Hi, im trying to get the data displayed in a QTableWidget, everything comes from a database and some calculations to the data itself, everytime i want to retrieve the data from a cell using the follow code, my program wont compile with the follow error error: use of deleted function 'QLineEdit::QLineEdit(const QLineEdit&) the table was made with Qt Designer
QLineEdit a = widget_PP.Registros_General->cellWidget(1,1)->findChild<QLineEdit>();
as far as i know the cellwidget retrieves the data inside the qwidget, i also used a qobject_cast but i got a similar error
QLineEdit a = qobject_cast<QLineEdit>(widget_PP.Registros_General->cellWidget(0,0));
i need the information display on the QTableWidget so i can send it to my printer, any idea where i might be wrong? i did try using item(), but that wont work because im using a QlineEdit
@Lightshadown
Read the docs carefully! BothfindChild<QLineEdit>();
andcellWidget(0,0)
will return a pointer to the widget. Your code is written for returning the widget itself, which is the cause of the error messages:QLineEdit *a = widget_PP.Registros_General->cellWidget(1,1)->findChild<QLineEdit>(); QLineEdit *a = qobject_cast<QLineEdit *>(widget_PP.Registros_General->cellWidget(0,0));
Of course these will only find such a
QLineEdit
if you have previously gonesetCellWidget()
. -
@Lightshadown
Read the docs carefully! BothfindChild<QLineEdit>();
andcellWidget(0,0)
will return a pointer to the widget. Your code is written for returning the widget itself, which is the cause of the error messages:QLineEdit *a = widget_PP.Registros_General->cellWidget(1,1)->findChild<QLineEdit>(); QLineEdit *a = qobject_cast<QLineEdit *>(widget_PP.Registros_General->cellWidget(0,0));
Of course these will only find such a
QLineEdit
if you have previously gonesetCellWidget()
.@JonB i did follow your advice and used the pointer, my error was the lack of the pointer and now its working properly, thanks
working code:QLineEdit *a = widget_PP.Registros_General->cellWidget(1,1)->findChild<QLineEdit*>(); // this works QLineEdit *a = qobject_cast<QLineEdit*>(widget_PP.Registros_General->cellWidget(1,1)) // doing object cast works as well