I am trying to import some data from a .csv file using a modified version of FileIO. I am supposed to use this data to show axis posture information. Therefore, values should be updated automatically every second. Then I created Q_PROPERTIES for every variable and created the code which gets data from the CSV file. I also added emit valueChanged() after every changing process.
void FileIO::getData()
{
if (mSource.isEmpty()){
emit error("source is empty");
}
QFile file(mSource);
if (file.open(QIODevice::ReadOnly) ) {
QString line;
while (!file.atEnd()) {
QByteArray line = file.readLine();
xValue = line.split(',')[0].toFloat();
emit xValueChanged();
yValue = line.split(',')[3].toFloat();
emit yValueChanged();
zValue = line.split(',')[4].toFloat();
emit zValueChanged();
//Sleep(1000);
qDebug()<< xValue <<yValue << zValue;
}
file.close();
} else {
emit error("Unable to open the file");
}
}
So far, everything was fine but to spark the importing process I used Component.onCompleted.
FileIO{
id: dataCSV
source: "C:/Users/Halil/yedekleme/Belgeler/build-serialGui-Desktop_Qt_5_14_2_MinGW_32_bit-Release/data.csv"
}
Component.onCompleted: {
dataCSV.getData()
}
...
Entity
{
id: satEntity
components: [
SceneLoader
{
id: sceneLoader
source: "sat.stl"
},
Transform {
id:satTransform
rotationX: dataCSV.xValue
rotationY: dataCSV.yValue
rotationZ: dataCSV.zValue
}
]
}
And the problem is I have to use these data to rotate a 3D object in real-time, but the engine doesn't load the ApplicationWindow before the Component.onCompleted is done. I see the values are updating -printing them to screen- but the transformer component cannot use them because the ApplicationWindow is not initialized before Component.onCompleted finishes, therefore I only see the last values.