PDA

View Full Version : Connecting tableWidget signal and external slot



qutron
17th November 2010, 13:48
Hi there!
I want to connect cellDoubleClicked() from tableWidget to custom slot.
In my main.cpp i have instance of QMainWindow class - window.
I tried


QObject::connect( window, SIGNAL(cellClicked(int, int)),window, SLOT(onCellClicked(int, int)));

but it doesn't work. onCellClicked(int, int) is my custom slot. Any suggestions?

Zlatomir
17th November 2010, 14:04
You must use the cellDoubleClick(int, int) (http://doc.qt.nokia.com/4.7/qtablewidget.html#cellDoubleClicked) signal of your tableWidget object.

So, if your tableview member is public, the connect should look something like:
QObject::connect( window->Your_tableWidget_name, SIGNAL(cellDoubleClicked(int, int)),
window, SLOT(onCellClicked(int, int))
);

But most likely the tableWidget is private (or the ui object or pointer is private, depends on your project), then you can create another signal in your mainwindow class, connect the cellDoubleClicked(int, int) signal with the signal you create (you can connect two signals) and use this signal to finally connect to the slot that you need to execute.

Lykurg
17th November 2010, 14:05
the first argument has to be a pointer to your table widget.

EDIT: too late.

qutron
17th November 2010, 14:12
But most likely the tableWidget is private (or the ui object or pointer is private, depends on your project), then you can create another signal in your mainwindow class, connect the cellDoubleClicked(int, int) signal with the signal you create (you can connect two signals) and use this signal to finally connect to the slot that you need to execute.

Just tried to do that. It works))

Thanks.