How can i correctly make the definition of class in cpp
Hello ,
I am really new in c++ development .
I created a class Backend .
In Backend.h I defined a constructor .
So I would like t redefine correctly my class In Backend.cpp
thank you
this is the def in Backend.h
1 2 3 4 5 6 7 8 9 10
|
public:
Backend(QObject *parent = nullptr): QObject(parent), m_fetchFrameTimer(this){
connect(&m_fetchFrameTimer, & QTimer::timeout, this, &Backend::fetchNextDataFrame);
m_fetchFrameTimer.setSingleShot(true);
m_canDevice = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), QStringLiteral("can0"));
connect(m_canDevice, &QCanBusDevice::framesReceived, this, &Backend::onFramesReceived);
connect(m_canDevice, &QCanBusDevice::framesWritten, this, &Backend::onFramesWritten);
}
| |
In my Backend.cpp ,
I tried this :
1 2 3 4
|
Backend::Backend(QObject *parent ) :QObject(parent), m_fetchFrameTimer(new QTimer(this))
{
| |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// class definition
class Backend {
public:
Backend( QObject *parent = nullptr ); // member declaration
};
// function definition (aka implementation)
Backend::Backend( QObject *parent )
: QObject(parent), m_fetchFrameTimer(this)
{
connect(&m_fetchFrameTimer, & QTimer::timeout, this, &Backend::fetchNextDataFrame);
m_fetchFrameTimer.setSingleShot(true);
m_canDevice = QCanBus::instance()->createDevice(QStringLiteral("socketcan"), QStringLiteral("can0"));
connect(m_canDevice, &QCanBusDevice::framesReceived, this, &Backend::onFramesReceived);
connect(m_canDevice, &QCanBusDevice::framesWritten, this, &Backend::onFramesWritten);
}
| |
Last edited on
Topic archived. No new replies allowed.