Reputation: 41
I was trying to make QLCDNumber clickable, by inheriting a new class from it. All it does is define a mouseReleaseEvent(QMouseEvent *e) sending a clicked() signal. I think my code is correct, but it can't find the signal (unresolved external symbol on clicked() inside mouseReleaseEvent()
//myLCDNumber.h
#ifndef MYLCDNUMBER_H
#define MYLCDNUMBER_H
#include <QLCDNumber>
#include <QMouseEvent>
class myLCDNumber : public QLCDNumber
{
public:
myLCDNumber(uint numDigits);
~myLCDNumber();
void mouseReleaseEvent(QMouseEvent *e);
signals:
void clicked(void);
};
#endif // MYLCDNUMBER_H
//myLCDNumber.cpp
#include "mylcdnumber.h"
myLCDNumber::myLCDNumber(uint numDigits):QLCDNumber(numDigits){}
myLCDNumber::~myLCDNumber(){}
void myLCDNumber::mouseReleaseEvent(QMouseEvent *e)
{
qDebug("Click check");
if (e->button() == Qt::LeftButton)
emit myLCDNumber::clicked();
}
EDIT : I checked the SOURCES list for all my files to be correctly referenced in my project file, and I rerun qmake. No change.
Upvotes: 4
Views: 4000
Reputation: 1
I know this was answered 9 years back, but the problem on my side was caused by not exporting the symbols correctly from a dll. Silly mistake to make, but might safe someone the testing path to eventual epiphany.
class _declspec(dllexport) LibrarianMainWidget final : public QWidget
{
Q_OBJECT
public:
explicit MyWidget(Model model);
void InitLayout(QWidget* parent);
signals:
void NewAssetCreated();
}
Upvotes: 0
Reputation: 8410
Your problem is that you use signals and/or slots without using Qt's Meta Object Compiler. Add the Q_OBJECT
Macro to your class definition and it'll work:
//myLCDNumber.h
#ifndef MYLCDNUMBER_H
#define MYLCDNUMBER_H
#include <QLCDNumber>
#include <QMouseEvent>
class myLCDNumber : public QLCDNumber
{
Q_OBJECT
public:
myLCDNumber(uint numDigits);
~myLCDNumber();
void mouseReleaseEvent(QMouseEvent *e);
signals:
void clicked(void);
};
#endif // MYLCDNUMBER_H
Don't forget to add the header file to the HEADERS
variable and rerun qmake before building again.
Upvotes: 11
Reputation: 724
You need to add Q_OBJECT macro to your class declaration and run qmake...maybe to rebuild your project
Upvotes: 0