Custome destructor in C++
Unsolved
QML and Qt Quick
-
I am developing an app in which I start a timer in constructor and stop it in destructor but I get an error namely:
'class Example' has no member named 'level'.
My Code:
Example.h
class Example: public QObject { Q_OBJECT public: explicit Example(QObject *parent = 0); ~Example(); ... }
Example.cpp:
Example::Example(QObject *parent) : QObject(parent) { timer = new QTimer(this); connect(timer, SIGNAL(timeout()),this,SLOT(update_func())); timer->start(1000); } Example::~Example(){ timer->stop(); }
please help.
-
Hi,
Do you have any "level" variable somewhere that you are calling ?
-
Did you properly declare all the methods and implement the slot and getter ?
-
@SGaist I think so:
void Example::set_level(int level){ if (level != g_level){ g_level = level; emit level_changed(g_level); } } void Example::update_func(){ int level = get_level(); if (level != INVALID){ set_level(level); } } int Example::cur_level(){ return g_level; }
-
You declared the getter method to be
level
. I don't see that method anywhere in your code. -
@Ahti said in Custome destructor in C++:
What Is a getter ?
In your header, you wrote this:
Q_PROPERTY(int level READ level WRITE set_level NOTIFY level_changed)
You're saying that you have these functions:
- Getter method (READ):
level()
- Setter method (WRITE):
set_level()
- Signal (NOTIFY):
level_changed()
You told Qt that your getter is called
level()
, but it is actually calledcur_level()
. - Getter method (READ):