价值从QVector消失

Efo*_*fog 0 c++ qt dictionary vector

我有QMapQVector内:

QMap<QString, QMap<QGraphicsView*, QVector<float>>> graphs;
Run Code Online (Sandbox Code Playgroud)

我正在尝试执行此代码:

QVector<float>* graphValues = &(graphs.values()[i - values.count()].values()[0]);

graphValues->push_back(1234);

qDebug() << "=== Debug messages ===\r\n";
qDebug() << "i - values.count() = " << i - values.count();
qDebug() << "graphValues = " << graphValues;
qDebug() << "*graphValues = " << *graphValues;
qDebug() << "graphs = " << graphs;
qDebug() << "graphs.values()[i - values.count()].values()[0] = " << graphs.values()[i - values.count()].values()[0];
Run Code Online (Sandbox Code Playgroud)

它给了我输出:

i - values.count() =  0
graphValues =  0x2000e90
*graphValues =  QVector(1234)
graphs =  QMap(("tempgraph", QMap((QGraphicsView(0x1fb1920) ,  QVector() ) ) ))
graphs.values()[i - values.count()].values()[0] =  QVector()
Run Code Online (Sandbox Code Playgroud)

那么,我的价值在哪里?使用指针i等待我的值graphs,但它消失了.

Ama*_*tel 5

QMap::values()方法返回临时对象.您无法通过更改原始数据来更改原始数据.你应该使用迭代器,或者QMap::operator[]以某种方式.