tags:

views:

221

answers:

1

I have a QTableView that I need to get the selectionChanged event from. I can't seem to get the connect working. I have:

MyWidget.h

...

protected slots:
 void slotLoadTransaction(const QItemSelection & selected, const QItemSelection & deselected);
private:
 QTableView table;

...

MyWidget.cpp ...

 connect(
  table->selectionModel(),
  SIGNAL(selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)),
  this,
  SLOT(slotLoadTransaction(const QItemSelection & selected, const QItemSelection & deselected))
 );

...

At runtime, I get "No such Signal" errors.

+4  A: 

You need to remove the variable names from the SIGNAL and SLOT macros:

 connect(
  table->selectionModel(),
  SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
  SLOT(slotLoadTransaction(const QItemSelection &, const QItemSelection &))
 );

Connect is essentially looking at the function signature and the variable names confuse it.

Kaleb Pederson
+1 You seem to have forgottent the "this" in your statement (the parameter between SIGNAL and SLOTS) tho, didn't you ?
Andy M
Andy, I think I can figure that little bit out.Kaleb, thank you sir! Works like a jewel :)
David Souther
@Andy - No, I purposefully left it out. The above syntax is more concise and equivalent whenever the recipient is "this." There are two connects, a connect instance method (which I used) and a static method. See the docs for more information.
Kaleb Pederson
@Andy: He didn't actually forget the "this"... if you inherit from a QObject, you have an overloaded version of connect that takes the parameters given, and assumes "this" as the object for the slot.
Caleb Huitt - cjhuitt
@Kaleb and Caleb :) Thanks a lot for the tips ! I didn't know that !
Andy M