Search code examples
qtsignals-slotsqtablewidgetqtablewidgetitem

QTableWidget itemDoubleClicked signal link to textEdit


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?


Solution

  • 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.