for (int i = 0; i < agvs.size(); i++) { //畫出路綫 if (i < paths.size() && paths[i].size() > 1 && paths[i][0] != nullptr) { QPainterPath path; path.moveTo(paths[i][0]->x, paths[i][0]->y); for (int k = 1; k < paths[i].size(); k++) { if (paths[i][k] != nullptr) { path.lineTo(paths[i][k]->x, paths[i][k]->y); } } if (!path.isEmpty()) { QPainter painter(this); if (painter.isActive()) { painter.setPen(QPen(Qt::red, 20)); painter.drawPath(path); } } } },修改爲:畫出agv的整個路徑
时间: 2023-12-20 16:07:47 浏览: 62
可以将上述代码修改为:
```
for (int i = 0; i < agvs.size(); i++) {
if (i < paths.size() && paths[i].size() > 1 && paths[i][0] != nullptr) {
QPainterPath path;
path.moveTo(paths[i][0]->x, paths[i][0]->y);
for (int k = 1; k < paths[i].size(); k++) {
if (paths[i][k] != nullptr) {
path.lineTo(paths[i][k]->x, paths[i][k]->y);
}
}
if (!path.isEmpty()) {
agvs[i]->setPath(path); // 设置AGV的整个路径
QPainter painter(this);
if (painter.isActive()) {
painter.setPen(QPen(Qt::red, 20));
painter.drawPath(path);
}
}
}
}
```
这样就可以同时画出AGV的整个路径,并将路径保存在AGV对象中。注意需要在AGV类中添加`setPath`方法来保存路径。
阅读全文