I wrote this code sample and found that it definitely hasn't looking good but I struggled trying to optimize it. Maybe somebody can help me with it. Qt5.
int MainWindow::readVariable(QVector<double> &value, QVector<double> &time, QString type, QFile *f)
{
int buffer_size = 0;
quint64 read_bytes = 0;
while (1)
{
if (type == "u_int32_t")
{
buffer_size = sizeof(unsigned);
unsigned dest = 0;
read_bytes = f->read(reinterpret_cast<char*>(&dest), buffer_size);
value.append(dest);
break;
}
if (type == "int32_t")
{
buffer_size = sizeof(int32_t);
int32_t dest = 0;
read_bytes = f->read(reinterpret_cast<char*>(&dest), buffer_size);
value.append(dest);
break;
}
/* ... and so on for many-many variable types */
}
}
"type" value I read from the XML-file earlier.