使用 qhash->keys 初始化 qlist
在执行以下操作时是否会发生错误的初始化:
pdList = new QList<QString>(somehash->keys());
其中,
pdList = QList<QString>*
somehash = QHash<QString,QList<someobject*> > *
此操作在构造函数中启动时发生。
询问的原因是有时我
pdlist->contains(someqstring)
在调用构造函数后执行正确操作时会发生崩溃。 崩溃位于
/usr/local/Trolltech/Qt-4.6.3-410wrl/include/QtCore/qlist.h:93
/usr/local/Trolltech/Qt-4.6.3-410wrl/include/QtCore/qlist.h :757
Can there occur a bad initialization while doing the following things:
pdList = new QList<QString>(somehash->keys());
where,
pdList = QList<QString>*
somehash = QHash<QString,QList<someobject*> > *
this operation happens at startup in constructor.
The reason for asking is sometimes i get a crash while doing
pdlist->contains(someqstring)
rigth after the constructor is called.
The crash is in
/usr/local/Trolltech/Qt-4.6.3-410wrl/include/QtCore/qlist.h:93
/usr/local/Trolltech/Qt-4.6.3-410wrl/include/QtCore/qlist.h:757
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
注意模板的使用,如下所示。您应该使用 <>人物:
Pay attention to template usage like below . You should use <> characters:
您应该使用 QList
QList< QString >
,与QList(QString)
相反。You should use
QList< QString >
, as opposed toQList(QString)
.在提供额外代码之前进行初步猜测。
也许您所依赖的初始化顺序是无效的。以下的一些变体:
pdList
将始终在somehash
之前初始化。决定它的是它们作为数据成员列出的顺序,而不是在构造函数中。有些编译器会让你将它们以不正确的顺序放入构造函数初始化列表中;其他人则不会。这只是一个猜测;如果您提供更多信息,社区将能够更好地提供帮助。
Preliminary guess until additional code is provided.
Perhaps you are depending on the order of initialization that is invalid. Some variant of the following:
pdList
will always be initialized beforesomehash
. It is the order they are listed as data members, not in the constructor, that determines it. Some compilers will let you put them in the incorrect order in the constructor initialization list; others will not.This is just a guess; if you provide more information, the community will be better able to help.