I read data from file, line by line, and each will be stored as an element in a vector.
std::vector<one_screw*> m_recorded_screw;
Here is the code:
typedef struct{
int id;
float x;
float y;
float z;
float dis;
}one_screw;
void read_file(...)
{
for( QString line
= in.
readLine();
!line.
isNull(); line
= in.
readLine()) {
line = line.trimmed();
one_screw *a_screw;
a_screw->id = list.at(0).toInt();
a_screw->name = list.at(1); //->prolem
a_screw->x = list.at(2).toFloat();
a_screw->y = list.at(3).toFloat();
a_screw->z = list.at(4).toFloat();
a_screw->dis = list.at(5).toFloat();
a_screw->checked = list.at(6); //->prolem
a_screw->tool = list.at(7); //->prolem
m_recorded_screw.push_back(a_screw);
}
}
typedef struct{
int id;
QString name;
float x;
float y;
float z;
float dis;
QString checked;
QString tool;
}one_screw;
void read_file(...)
{
QTextStream in(&file);
for( QString line = in.readLine(); !line.isNull(); line = in.readLine())
{
line = line.trimmed();
one_screw *a_screw;
QStringList list = line.split(" ", QString::SkipEmptyParts);
a_screw->id = list.at(0).toInt();
a_screw->name = list.at(1); //->prolem
a_screw->x = list.at(2).toFloat();
a_screw->y = list.at(3).toFloat();
a_screw->z = list.at(4).toFloat();
a_screw->dis = list.at(5).toFloat();
a_screw->checked = list.at(6); //->prolem
a_screw->tool = list.at(7); //->prolem
m_recorded_screw.push_back(a_screw);
}
}
To copy to clipboard, switch view to plain text mode
I am not sure whether I must use iterator to access the QStringList element. But for the marked lines I have run-time error "Access violation writing location...". In the struct I cannot use QString? Or I use QStringList wrongly? Help!
Bookmarks