Hi all. I'm working on car simulator. The core is the class car who implements the physics of veicles. This class have a public function that return Qtime, the minimum time to go through a part of a track.
One of the outputs of my application would be a table in a sqlite db like this:
Lap | iDCar | LapTime | TotalTime | Position
For this i have implemented a code like this (i'm not posing the original code couse a lot of function's names are not in english)
QString query
= " Insert into tablename ";
QVector<Part> track;
QVector<Car> cars;
//fill vectots
QMap<QString, QTime> total_time;
for(int lap=1; lap<=nLap; lap++)
{
for(int id=0; id<cars.size(); id++)
{
lapTime
= QTime(0,
0,
0,
0);
for(int part=0; part<track.size(); part++)
{
partTime = cars[id].getTime(track.at(part));
lapTime
= lapTime.
addMsec(partTime.
msecTo(QTime(0,
0)));
//really, qAbs() of partTime.msecTo()total_time
[cars.
at(id
).
pilotId()] = total_time
[cars.
at(id
).
pilotId()].
addMsec(lapTime.
msecTo(QTime(0,
0)));
s.append( // built a "select - union all" query.
}
}
}
qsqlQuery q;
q.exec(query);
QString query = " Insert into tablename ";
QVector<Part> track;
QVector<Car> cars;
//fill vectots
QMap<QString, QTime> total_time;
QTime lapTime, partTime;
for(int lap=1; lap<=nLap; lap++)
{
for(int id=0; id<cars.size(); id++)
{
lapTime = QTime(0,0,0,0);
for(int part=0; part<track.size(); part++)
{
partTime = cars[id].getTime(track.at(part));
lapTime = lapTime.addMsec(partTime.msecTo(QTime(0,0))); //really, qAbs() of partTime.msecTo()
total_time[cars.at(id).pilotId()] = total_time[cars.at(id).pilotId()].addMsec(lapTime.msecTo(QTime(0,0)));
s.append( // built a "select - union all" query.
}
}
}
qsqlQuery q;
q.exec(query);
To copy to clipboard, switch view to plain text mode
Now the problem is that i can't figure out how to get the position of the car at that determinated lap. I know that i have to do something with the QMap total_time that have unique car id as keys, and total time as values, but i don't know how to sort QMap values witout losing the corrispondence with keys.
I hope someone could help me, and i apologize for my English.
Bookmarks