简体   繁体   English

QMap :: freeData()上的Qt核心

[英]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: 使用QMap的代码如下所示:

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

The foreach line is where the QMap is retrieved with the getter method. foreach行是使用getter方法检索QMap的位置。 Anyone know what QMap::freeData() does? 有人知道QMap :: freeData()做什么吗? The only references I can find anywhere on the internet are the actual QMap.h source. 我在互联网上任何地方都能找到的唯一参考文献是实际的QMap.h源。 It looks like the method is used in the QMap destructor. 看起来QMap析构函数中使用了该方法。 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. 无论如何,我想如果我对freeData()有所了解,我也许就能弄清楚并修复这个核心。

You don't need to know anything about freeData . 您不需要了解关于freeData任何信息。 The contents of the map field within myClass3 are corrupt, and getMap() shallow-copies a map instance that has been damaged. myClass3中map字段的内容已损坏,并且getMap()浅表复制了已损坏的地图实例。 freeData works fine as long as the object it works with has not been damaged by errant code. freeData的对象未被错误的代码损坏, freeData正常工作。

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. 用互斥锁保护对数据结构的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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