I try to implement cpp variables to qml using Q_PROPERTY. First, I have created Q_PROPERTY of float numbers xValue, yValue, and zValue in the header file.
fileio.h
...
Q_PROPERTY(int xValue
MEMBER xValue
NOTIFY xValueChanged)
Q_PROPERTY(int yValue
MEMBER yValue
NOTIFY yValueChanged)
Q_PROPERTY(int zValue
MEMBER zValue
NOTIFY zValueChanged)
...
Then I also make them private and created their signal functions.
signals:
void xValueChanged();
void yValueChanged();
void zValueChanged();
private:
float xValue,yValue,zValue;
After that, I have assigned a changeable variable to these float numbers in fileio.cpp file
...
xValue = (line.split(',')[0]).toFloat();
yValue = (line.split(',')[4]).toFloat();
zValue = (line.split(',')[5]).toFloat();
...
Lastly, I tried to use them in QML
FileIO{
id: dataCSV
source: "qrc:/data.csv"
}
Component.onCompleted: {
console.log(FileIO.xValue)
}
but qml returnsundefined.
Now I have 2 main questions. The first is should I define a function that updates values of variables, because (as I know) in cpp it is not needed to create an update function. And the second one is, if the return doesn't cause from the lack of update function, what should I do to use and read these variables' values in qml?