QHash static member error
Hi all,
I am using Pardus(Linux) and gcc 4.
I have static QHash member .I can compile my code correctly but when i want to run my code and insert any data it gives segmentation fault error.My Code is like that:
//initializer.h
Code:
class initializer
{
public:
static QHash<QString,QString> myHash;
}
//initializer.cpp
Code:
QHah<QString,QString> initializer::myHash;
{
myHash.insert(str1,str2);
}
It gives runtime segmentation fault error.is anybody know where is the problem?
Thanks in advance
Ramazan
Re: QHash static member error
Run the application via debugger (gdb) and post the backtrace here.
Re: QHash static member error
when running with gdb it gives that output:
[Thread debugging using libthread_db enabled]
[New thread -1499507024(LWP 24685)]
Program received signal SIGSEGV Segmentation Fault
[Switching to thread -1499507024(LWP 24685)]
0x08057958 in QBasicAtomic::Operator!=()
Re: QHash static member error
You have to protect the hash for example with QReadWriteLock if you access it from multiple threads.
Re: QHash static member error
No i am using in only one thread since I think lock isn't necessary.
Re: QHash static member error
So what does the backtrace look like? Could you provide something compilable we could test ourselves?
Re: QHash static member error
I believe the static QHash is instantiated before QApplication.
Re: QHash static member error
Quote:
Originally Posted by
marcel
I believe the static QHash is instantiated before QApplication.
That shouldn't be any problem. QHash is not a QObject but a generic container, it doesn't depend anyhow on the application object.