当我将新的QGraphicsLineItem添加到QGraphicsPixmapItem的QList时,我的c ++程序崩溃了。 以下是该功能。
void MainWindow::linkComputerNodes(QList<Node*> routers)
{
for(int i=0;i<routers.length();i++)
{
scene->addItem(new Link(routers.at(i),routers.at(i+1)));
}
}
答案 0 :(得分:0)
也许在router.at(i + 1)关闭一个?即试图访问路由器[routers.length]
答案 1 :(得分:0)
你的for循环:
for(int i=0;i<routers.length();i++)
遍历列表中的每个路由器,然后在每个路由器之后直接添加链路。这意味着对于最后一个路由器,您尝试添加一个不存在的链接。尝试将循环更改为:
for(int i=0;i<routers.length() - 1;i++)
这样您只需在现有路由器之间添加链接。