Solved Other class read unchanged variable value
-
@sierdzio its necessary in this case? I have exacly same config in other project, and it work good
-
@BD9a said in Other Thread in my app dont get changed variable value:
@sierdzio its necessary in this case? I have exacly same config in other project, and it work good
Yes. Without
NOTIFY
, QML engine has no idea that value has updated. -
@sierdzio It could be useful, but I dont think it's my problem. In other project
Q_PROPERTY
withoutNOTIFY
work's good, and probably one strong diffrence is that additional thread.b_drink
variable is changing it's value, but function in other thread reading unchanged value.Removed this additional Thread (I dont really need this, those loops operate on ~3sec interval) and saw sth really weird. I changed this button to just print
b_dring
variable value (hardcoded asfalse
) - in same class it printsfalse
, in loop class it printingtrue
wtf... -
@BD9a minimal compileable example, please.
-
There is current code:
https://github.com/BD9a/testLoop/loop.cpp
printingb_drink
defined inConfig/config.h
-
Are you sure your testapp does not crash? 'Config *config;' is unitialized...
-
@Christian-Ehrlicher It doesnt crash
Current value is: false true true true
-
@BD9a Please fix your code, it can't work as I already explained.
-
@Christian-Ehrlicher how it should be done? In my opinion it should work (maybe cuz I dont understand it well?)
-
@BD9a I'm not entirely sure, what's going, or to be precise why everything doesn't go up in flames, but it is running on my pc and it shoudn't.
You can force this on your side as well by properly initializing the Config * inside Loop to a nullptr.
private: Config *config = nullptr;
that will crash, and it should.
Here, what to do to fix this:
Enable writing & storing
void Config::w_drink(bool value) { qDebug() << "Current value is: " << b_drink; if( b_drink == value) return; b_drink = value; //emit stateChanged(value); }
Pass the Config object on (from main.cpp) on. for example like this:
//loop.h explicit Loop(Config *conf, QObject *parent = nullptr); ... private: Config *config = nullptr; //loop.cpp Loop::Loop(Config *conf, QObject *parent) : QObject(parent) , config(conf){ flaskNo1 = new QTimer(this); flaskNo2 = new QTimer(this); flaskNo3 = new QTimer(this); flaskNo4 = new QTimer(this); flaskNo5 = new QTimer(this); connect(flaskNo1, SIGNAL(timeout()),this,SLOT(drinkNo1())); connect(flaskNo2, SIGNAL(timeout()),this,SLOT(drinkNo2())); connect(flaskNo3, SIGNAL(timeout()),this,SLOT(drinkNo3())); connect(flaskNo4, SIGNAL(timeout()),this,SLOT(drinkNo4())); connect(flaskNo5, SIGNAL(timeout()),this,SLOT(drinkNo5())); startLoop(); } //main.cpp ... Config config; config.create(); KeyTranslator ktr; Loop loop(&config); ...