QTableWidget itemDoubleClicked signal link to textEdit
-
18-02-2021 - |
Frage
i have a populated tableWidget and i want to select the row header upon doubleClick and grab the text in the row header then populate a textEdit with it.
i have:
connect(ui->tableWidget, SIGNAL(itemDoubleClicked(QTableWidget*)),ui->textEdit, SLOT(on_tableWidget_itemDoubleClicked(QTableWidgetItem*)));
void on_tableWidget_itemDoubleClicked(QTableWidgetItem *item)
{
QString selectedName = item->text();
ui->textEdit->setText(selectedName);
}
and not only is the focus not changing when i run the code buh nothing is happening to the textEdit... Am i missing something here?
Lösung
The connection should be
connect(ui->tableWidget, SIGNAL(itemDoubleClicked(QTableWidget*)),
this, SLOT(on_tableWidget_itemDoubleClicked(QTableWidgetItem*)));
provided that the slot is defined in your class.
Andere Tipps
With the slot name format ("on_widgetName_signalName
") and because the tableWidget
belongs to a generated ui, the connection should be done automatically by the line ui->setupUi(this);
you have in your constructor.
So, you can remove the connect
call, but you should check that on_tableWidget_itemDoubleClicked
is declared as a slot, and that the macro Q_OBJECT
was included in the class definition.