November 12, 2010

dpatrick dpatrick
Lab Rat
11 posts

[Solved] No such signal - My own class

 

Dear all,

I created my own PushButton to receive a signal when my button get focus. Please see code below:

  1. class MyPushButton : public QPushButton
  2. {
  3.     Q_OBJECT
  4.  
  5. public:
  6.     MyPushButton(QWidget *parent = 0);
  7.  
  8. signals:
  9.     void getFocus();
  10.  
  11. protected:
  12.     void focusInEvent (QFocusEvent * event);
  13.  
  14. };
  15.  
  16. MyPushButton::MyPushButton(QWidget *parent) :
  17.     QPushButton(parent)
  18. {
  19. }
  20.  
  21. void MyPushButton::focusInEvent (QFocusEvent * event)
  22. {
  23.     emit getFocus();
  24.     QPushButton::focusInEvent(event);
  25. }

And in the main application I connect the signal to the slot.

  1. connect(ui->btn1, SIGNAL(gotFocus()), this, SLOT(gotFocus1()));

When I start the application, I receive the following message:

  1. Object::connect: No such signal MyPushButton::gotFocus() in ../page1.cpp:26
  2. Object::connect: (sender name: 'btn1')
  3. Object::connect: (receiver name 'Page1')

So, what is wrong in my code? Any ideas?

I promoted my QPushButton to MyPushButton.

Thanks a lot.

4 replies

November 12, 2010

iunknwn iunknwn
Lab Rat
34 posts

Typo: Error is for gotFocus. Signal name is getFocus.

 Signature 

Vista x64 with Qt 4.8.2 and VS2010

November 12, 2010

iunknwn iunknwn
Lab Rat
34 posts

Good Programming Practice: If you are using Visual Studio, let intellisense type the signal out as

  1. connect(sender, SIGNAL(sender->signalName())....

Once you get it filled, delete “sender->”. This way you can never get the signal name typed incorrectly.

 Signature 

Vista x64 with Qt 4.8.2 and VS2010

November 12, 2010

Alexander Kuchumov Alexander Kuchumov
Lab Rat
377 posts
iunknwn wrote:
Good Programming Practice: If you are using Visual Studio, let intellisense type the signal out as Once you get it filled, delete “sender->”. This way you can never get the signal name typed incorrectly.

or use QtCreator, it shows available signals when you write code.

November 12, 2010

dpatrick dpatrick
Lab Rat
11 posts

Thanks a lot, I could not see my mistake.

 
  ‹‹ JObs with QMdiSubWindow!      QList copy constructor ››

You must log in to post a reply. Not a member yet? Register here!