【问题标题】:index out of range C++/Qt索引超出范围 C++/Qt
【发布时间】:2013-02-25 22:00:34
【问题描述】:

QList::operator[] 中的 ASSERT 失败:“索引超出范围”,为什么?

QList<int>    tanksLevel;
......
for(int i=0; i < 6; i++)
   tanksLevel[i] = rand() %51;

【问题讨论】:

  • 可能您的索引超出范围:)

标签: c++ qt


【解决方案1】:

表示i &gt;= tanksLevel.size()。检查那个。你可能想先用正确的大小初始化你的列表,或者使用QList::append而不是operator[]

【讨论】:

  • 如何将六个值放入 tankLevel ?
  • QList&lt;int&gt; tanksLevel(6); //using contructor, or... tanksLevel.resize(6); //after contruction, or... for(...) tanksLevel.append(newValue); //appending new value after each iteration
猜你喜欢
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-20
  • 2013-08-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多