PDA

View Full Version : QHash static member error



ramazangirgin
5th February 2008, 09:12
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


class initializer
{
public:
static QHash<QString,QString> myHash;
void insertToHash(QString str1,QString str2);
}


//initializer.cpp



QHah<QString,QString> initializer::myHash;
initializer::insertToHash(QString str1,QString str2)
{
myHash.insert(str1,str2);
}






It gives runtime segmentation fault error.is anybody know where is the problem?
Thanks in advance
Ramazan

jpn
5th February 2008, 09:34
Run the application via debugger (gdb) and post the backtrace here.

ramazangirgin
5th February 2008, 10:01
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!=()

jpn
5th February 2008, 10:09
You have to protect the hash for example with QReadWriteLock if you access it from multiple threads.

ramazangirgin
5th February 2008, 10:58
No i am using in only one thread since I think lock isn't necessary.

jpn
5th February 2008, 11:03
So what does the backtrace look like? Could you provide something compilable we could test ourselves?

marcel
5th February 2008, 11:19
I believe the static QHash is instantiated before QApplication.

jpn
5th February 2008, 11:26
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.