简体   繁体   中英

Qt core on QMap::freeData()

I have the following stack trace on a core:

#1 0x..... in raise()
#2 0x..... in abort()
#3 0x..... in xehInterpretSavedSigaction()
#4 0x..... in xehExceptionHandler()
#5 <signal handler called>
#6 0x..... in QMap<int, myClass#1>::freeData(QMapData*) ()
#7 0x..... in myClass#2::myClass#2Method()
#8 0x..... so on and so forth

The code that uses the QMap looks like this:

     foreach (myClass::sturct1 conn, myClass3->getMap())
     {
         if (conn == x)
         {
             return conn;
         }
     }

The foreach line is where the QMap is retrieved with the getter method. Anyone know what QMap::freeData() does? The only references I can find anywhere on the internet are the actual QMap.h source. It looks like the method is used in the QMap destructor. The method name leads me to believe it is freeing up data. Anyway, I think if I knew more about freeData() I might be able to figure out and fix this core.

You don't need to know anything about freeData . The contents of the map field within myClass3 are corrupt, and getMap() shallow-copies a map instance that has been damaged. freeData works fine as long as the object it works with has not been damaged by errant code.

Since you're trying to access data from multiple threads, you must either:

  1. Operate from a separate instance of the shared data structure in each thread. The key point is: you have to create a copy in the thread that "owns" the source. You can then pass the copy to another thread and use it there. See this answer for example code.

  2. Protect the access to the data structure with a mutex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM