if (!paths[i].empty()) { std::cout << "path size: " << paths[i].size() << std::endl; QPainterPath path; for (int j = 0; j < paths[i].size(); j++) { // 修改循环条件 if (j == paths[i].size() - 1) break; // 添加判断语句 Node* current_node = paths[i][j]; Node* next_node = paths[i][j+1]; int x1 = current_node->x; int y1 = current_node->y; int x2 = next_node->x; int y2 = next_node->y; int x_draw1 = x1 * nodeSize + 200 + nodeSize/2; int y_draw1 = y1 * nodeSize + 50 + nodeSize/2; int x_draw2 = x2 * nodeSize + 200 + nodeSize/2; int y_draw2 = y2 * nodeSize + 50 + nodeSize/2; path.moveTo(x_draw1, y_draw1); path.lineTo(x_draw2, y_draw2); } painter.setPen(QPen(Qt::red, 2)); painter.drawPath(path); },一運行就卡死,怎麽修改
时间: 2023-11-27 14:55:03 浏览: 100
angular-paths:path.js 高级 API 的指令
可能是因为你的循环条件有问题,导致程序陷入了死循环,你可以尝试将循环条件修改为:
```cpp
for (int j = 0; j < paths[i].size() - 1; j++)
```
同时,为了避免程序崩溃,你也可以在循环内部添加判断语句,防止越界访问:
```cpp
if (j + 1 >= paths[i].size()) break;
```
这样就可以避免程序卡死了。
阅读全文