Results 1 to 8 of 8

Thread: QHash static member error

  1. #1
    Join Date
    Jul 2007
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question 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
    Qt Code:
    1. class initializer
    2. {
    3. public:
    4. static QHash<QString,QString> myHash;
    5. void insertToHash(QString str1,QString str2);
    6. }
    To copy to clipboard, switch view to plain text mode 
    //initializer.cpp
    Qt Code:
    1. QHah<QString,QString> initializer::myHash;
    2. initializer::insertToHash(QString str1,QString str2)
    3. {
    4. myHash.insert(str1,str2);
    5. }
    To copy to clipboard, switch view to plain text mode 


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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QHash static member error

    Run the application via debugger (gdb) and post the backtrace here.
    J-P Nurmi

  3. #3
    Join Date
    Jul 2007
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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!=()

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QHash static member error

    You have to protect the hash for example with QReadWriteLock if you access it from multiple threads.
    J-P Nurmi

  5. #5
    Join Date
    Jul 2007
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHash static member error

    No i am using in only one thread since I think lock isn't necessary.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QHash static member error

    So what does the backtrace look like? Could you provide something compilable we could test ourselves?
    J-P Nurmi

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHash static member error

    I believe the static QHash is instantiated before QApplication.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QHash static member error

    Quote Originally Posted by marcel View Post
    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.
    J-P Nurmi

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  4. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.