Hi all,
Is it mandatory to initialize QHash before insert ? I have a crash on insert, althought i do insert non NULL values with the right types. My hash is a data member.
Code:
QHash<QListWidgetItem* , QStringList> m_variablepaths ;
Printable View
Hi all,
Is it mandatory to initialize QHash before insert ? I have a crash on insert, althought i do insert non NULL values with the right types. My hash is a data member.
Code:
QHash<QListWidgetItem* , QStringList> m_variablepaths ;
Except for the copy constructor there is no such thing as "initializing". You're apparently doing something wrong when inserting, but without any code it is impossible to know.
also, if you're using a pointer as a key, a QHash may not be the best choice.
It falls in Qt method detach(). Is that of any help for guiding me towards solution ?
Is it important that I pass a pointer to QstringList, and not a stack QStringList ?
What is better then Qhash ? why is Qhash not a good choice ? Should I use QMap instead ?
I tried to initialize in constructor, and i tried with a QMap, with same result.
It is irrelevant what you pass as the "value" part of the hash. If you pass a QStringList, the hash table will make a copy of it if needed.
Look, throwing out random tidbits of information isn't helping anyone help you. Unless you post some code that actually demonstrates what you are doing, we're just pulling things out of thin air.Quote:
It falls in Qt method detach(). Is that of any help for guiding me towards solution ?
Given some of the other questions you've posted, the errors evident in that code, and the "hint" you've given here, my guess would be that the problem is that something you did prior to inserting values into the hash table has corrupted memory, and that the crash you are seeing is a side effect and not the actual problem.
Inserting a pointer into a hash table would in no way result in a call to detach() for anything, but if memory is corrupt, the code might be jumping off into some unknown place in your program and executing whatever it finds there.
If all you need is to associate a QStringList with a QListWidgetItem, then you could use the QListWidgetItem::data() and QListWidgetItem::setData() methods instead of building an external data structure to keep the association.Quote:
What is better then ? why is it not a good choice ?
Otherwise, QHash<> is fine for this purpose, QMap<> would work too but it is less efficient since it must keep its keys sorted.
I have the same problem posted here, but nobody seems to answer it. :(