ifoundinformationfromthisthreadandamstartingtowonderiftheinformationprovidedthereisrelevanttothecauseoftheisssuei ' m facing。
我从这篇帖子中找到了信息,开始怀疑提供的信息是否与我面临的问题的原因有关。
theqmaptakesthefollowingtemplatearguments :
QMap采用以下模板参数:
QMap QString,int
QMap QString,int
mymainissueisthati ' minitializingacubeclass,andwithinthatclasscontainsvariouscallswhicharesupposedtodoveryspecificthings。
我的主要问题是正在初始化多维数据集类。 这个类包含各种调用,这些调用需要做非常具体的事情。
oneinparticularrevolvesaroundsettinguptheclass ' qmapmembers。
其中最引人注目的是设置类的QMap成员。
Observe the following:
遵守以下几点:
mGeometry=new Geometry;
mGeometry-Init (;
mame ra=q vector 3d (10.0、10.0和10.0 );
mubeage.insert('cubes ',0 );
debugoutputfrommcubeage.insert (' cubes ',0 );
从mCubeage调试输出。 插入(“立方体”,0 );
//ascii兼容性
//ASCII兼容性
1 ) ((uh oh ) ) ) ) ) )。
1 ) )啊() ) ) )。
#ifndef QT_NO_CAST_FROM_ASCII
inline Qt _ ascii _ cast _ warn _ constructor qstring (const char * ch ) :d(fromascii_helper ) ch ) )
{}
2 )
2 )
模板
q _ inline _ templatetypenameqmap :3360 iteratorqmap 3360: insert (constkeyakey,
常数值)
{
detach (; //the called function
qma pdata :3360节点*更新[ qma pdata :3360 last level1];
qma pdata :3360 node * node=mutablefindnode (update,akey );
if(node==e ) {
节点=node _ create (d,update,akey,avalue );
} else {
concrete(node )-value=avalue;
}
返回迭代器(node;
}
3 )3) ) )。
3 )3) ) )。
ool操作器==(constqmapother ) const;
在线bool操作器!=(constqmapother ) const { return! (*this==other ); }
在线整数(常数)返回大小; }
在线bool isempty () const { return d-size==0; }
在线语音深度() if ) d-ref!=1) detach_helper ); //thecalledfunction/if statement
inline bool isDetached () const { return d-ref==1; }
inlinevoidsetsharable (bool sharable ) if (! 可伸缩(深度); d-sharable=sharable; }
inlineboolissharedwith (constqmapother ) const { return d==other.d; }
inlinevoidsetinsertinorder (bool ordered ) { d-insertInOrder=ordered; }
在线bool操作器!=(intvalue ) const
{
return _q_value!=value;
}
4 )4) ) )。
4 )4) ) )。
在线bool操作器!=(intvalue ) const
{
return _q_value!=value;
}
And.that's where it stops - BOOM,segmentation fault.accordingtosomeoftheqtforumsoutthere-intherealmofinternet-itisununt whichioriginallythoughtofdoingmainlybecauseofthefactthatonepossiblereasonforthishappeningcouldbeduetothefacttheqmapmay nothavebebebay yet,thefactthatit ' saclassmemberwhichhasadefaultconstructoribelievecontradictsthis。
……这样,即使它停止了,——也会繁荣起来,分割是错误的。 根据Qt的一些论坛,QMaps在互联网领域声明指针——是不明智的。 我本来以为是这样的事实造成的,一个可能的原因是这个事实可能导致QMap没有正确初始化。 但是它是类的成员,有默认的构造函数。 我认为这是矛盾的。
队列
问题
According to the above,why is this happening? What can be done about it?
根据上述,为什么会发生这种事? 我们能做什么呢?
Thoughts
我的想法
beforesomeonementionsthefactthati ' mpassingaconstchar * toaqstringparameter,ishouldnotethatihavealreadytriedddeclaringaqstrion
请注意,在被告知要将const char*传递给QString参数之前,您试图声明QString并将其作为参数传递。 我也应该注意到,我在Qt作者Ubuntu 11.10上执行了这个。
一个解决方案
#1
2
What can be done about it?
我们能做什么呢?
thereisonlyonething :运行yourprogramundervalgrind,and fix all problems you find。
只有一个:在valgrind下运行你的程序,解决你发现的所有问题。
Why is it happening? 世卫组织知识? you didn ' tprovideenoughinformation.maybestacksmash,maybeyouoverwrotepassedtheendofsomearrays,etc .
为什么会发生这种事? 谁知道? 你没有提供足够的信息。 可能是stack smash,也可能是重写了数组的末尾,等等。