Solved QTimer will not connect
-
Yes, Qt3, novice programmer. Please try to accommodate typos as I cannot copy paste from my work computer to here. It does run but the connect fails. Found another thread here, same topic, but don’t have the same error as that one.
The h file containsclass C_GL_Strip_Chart : public QGLWidget { … public slots: void interval_timer( void ); private: QTimer *m_timer; … }
The cpp file contains
C_GL_Strip_Chart::C_GL_Strip_Chart( QGLWidget * parent ) : QGLWidget( parent, “qglwidget”, 0, Qt::WStyle_DialogBorder) { … // That QGLWidget may be significant interval_timer(); // this call is sucessful m_timer = new QTimer( this, “strip_chart_timer” ); unsigned short return_value = 999; // gets changed to 0. Different type required here? return_value = connect( m_timer, SIGNAL( timeout()), this, SLOT( interval_timer() ) ); std::cout << “connect done, returned “ << return_value << “\n”; … }
Further down is
void C_GL_Strip_Chart ::interval_timer( void ) { std::cout << “called\n”; };
It compiles with no errors or warnings. When run the terminal window contains:
QObject::connect: No such slot QGLWidget::interval_timer() QObject::connect: (sender name: ‘strip_chart_timer’ ) QObject::connect: (receiver name: ‘qglwidget’ ) connect done, returned 0
I cannot figure out what is wrong here.
-
@BKBK said in QTimer will not connect:
Do you have Q_OBJECT macros right at the beginning of C_GL_Strip_Chart body?
-
@BKBK said in QTimer will not connect:
return_value = connect( m_timer, SIGNAL( timeout()), this, SLOT( interval_timer() ) );
this is one of the reasons I personally prefere the new (Qt5) SignalSlot syntax, compile time check of the connects ;-)
try
return_value = connect( m_timer, &QTimer::timeout, this, C_GL_Strip_Chart ::interval_timer );
-
@jsulm said in QTimer will not connect:
@BKBK said in QTimer will not connect:
Do you have Q_OBJECT macros right at the beginning of C_GL_Strip_Chart body?
Rookie and all, still, I am embarrassed at not thinking of that. Yes, that was my problem.
And yes, we really do need to upgrade. But,..., the best reasons in the world do not help.
Thank you
Edit
Two lines from the OPunsigned short return_value = 999; // gets changed to 0. Different type required here? return_value = connect( m_timer, SIGNAL( timeout()), this, SLOT( interval_timer() ) );
I saw that return value somewhere but cannot find any documentation about it.
Is there anything to discover what the return values mean and other functions that may have return values? -
@BKBK Take a look at the documentation: http://doc.qt.io/qt-5/qobject.html#connect