Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt QHash向量_Qt_Replace_Constants_Qhash_Qvector - Fatal编程技术网

Qt QHash向量

Qt QHash向量,qt,replace,constants,qhash,qvector,Qt,Replace,Constants,Qhash,Qvector,我有一个QHash-QHash,并试图将QVector中的值覆盖如下: void Coordinate::normalizeHashElements(QHash<QString, QVector<float> > qhash) { string a = "Cluster"; float new_value; float old_value; const char *b = a.c_str(); float min = getMinH

我有一个
QHash-QHash
,并试图将
QVector
中的值覆盖如下:

void Coordinate::normalizeHashElements(QHash<QString, QVector<float> > qhash)
{
    string a = "Cluster";
    float new_value;
    float old_value;
    const char *b = a.c_str();
    float min = getMinHash(qhash);
    float max = getMaxHash(qhash);

    QHashIterator<QString, QVector<float> > i(qhash);
        while (i.hasNext())
        {
            i.next();
            if(i.key().operator !=(b))
            {
                for(int j = 0; j<i.value().size(); j++)
                {
                    old_value = i.value().at(j);
                    new_value = (old_value - min)/(max-min)*(0.99-0.01) + 0.01;
                    i.value().replace(j, new_value);
                }
            }
        }
}
void坐标::normalizeHashElements(QHash-QHash)
{
字符串a=“集群”;
浮动新的_值;
浮动旧值;
const char*b=a.c_str();
float min=getMinHash(qhash);
float max=getMaxHash(qhash);
qhash迭代器i(qhash);
while(i.hasNext())
{
i、 next();
if(i.key().operator!=(b))
{

对于(int j=0;j错误消息告诉您试图在
const
实例上使用非
const
方法。在这种情况下,您试图在
const QVector
实例上调用
QVector::replace
。这主要是因为您正在使用
QHashIterator
,它只返回e> 常量
来自的引用

要解决这个问题,您可以在
QHash
上使用STL风格的迭代器而不是Java风格的迭代器:

QString b("Cluster");
QHash<QString, QVector<float> >::iterator it;
for (it = qhash.begin(); it != qhash.end(); ++it)
{
   if (it.key() != b)
   {
      for (int j=0; i<it.value().size(); j++)
      {
         old_value = it.value().at(j);
         new_value = (old_value-min)/(max-min)*(0.99-0.01) + 0.01;
         it.value().replace(j, new_value);
      }
   }
}
QString b(“集群”);
QHash::迭代器;
for(it=qhash.begin();it!=qhash.end();+it)
{
if(it.key()!=b)
{

for(int j=0;我非常感谢您的回复。我会尝试一下,一完成就留下反馈。@Mikaeyan不客气。别忘了接受有帮助的答案::-)