vertigo89
vertigo89

Reputation: 31

Qt, "no such signal" runtime error from child class, having Q_OBJECT macro

Using Qt 5.4, I'm having trouble with a signal emitted from a child class. This is the situation:

There is a

class Player : public QDialog{
Q_OBJECT
/*...*/
public slots: 
  void ReactToAdapter(Adapter::state_t newState);
private:
  Adapter* adapter;
}

The

class Adapter : public QObject{
Q_OBJECT
public:
  enum state_t {/*...*/}
signals:
  void StateChagned(state_t newState);
}

is purely virtual. One of its Implementations is given as

class AdapterCAN : public Adapter{
O_OBJECT
/*...*/
}

AdapterCAN is emitting the StateChagnedwithin one of its methodes.

state_t is visible everywhere through includes. All three classes have the Q_OBJECT macro.

When I try to do

Player::ConnectToCANBus(/*...*/){

  adapter = new AdapterCAN(/*...*/);

  connect(adapter, SIGNAL(StateChanged(Adapter::state_t), 
    this, SLOT(ReactToAdapter(Adapter::state_t));

}

This creates the error message QObject::connect: No such signal AdapterCAN::StateChanged(Adapter::state_t) in ..\player.cpp:90 during runtime.

It looks like the signal is not inherited!? Anyone having any ideas what I might be doing wrong? Thanks!

Upvotes: 2

Views: 579

Answers (2)

ShareMemory
ShareMemory

Reputation: 1

If anyone finds here, please check your connect function for errors. I once wrote such a stupid error, but the compiler did not give any error report.

connect(m_pInitEncFromDvd1, SIGNAL(signalFinish(int,QStirng)), 
    this, SLOT(slotDVD1InitFinish(int,QString)), 
    (Qt::ConnectionType)(Qt::ConnectionType::AutoConnection | Qt::ConnectionType::UniqueConnection));

Pay attention to

"SIGNAL(signalFinish(int,QStirng))"

, I accidentally write QString as QStirng, and it works perfectly after correction.

Upvotes: 0

vertigo89
vertigo89

Reputation: 31

Changing the definition of the signal to

class Adapter : public QObject{
/*...*/
  void StateChagned(state_t);
}

solved it. The qualified name has to be left out.

Thanks to @vahancho for pointing this out!

Upvotes: 1

Related Questions