A
A
Alexey Artyushkov2016-09-05 21:10:17
Qt
Alexey Artyushkov, 2016-09-05 21:10:17

Why does a SEGFAULT error occur when adding an element to a QMap?

Good day, colleagues! There is this code:

/*!
 * \brief createModelingObjects создает объекты для моделирования
 * \param modelingObjMgr менеджер объектов моделирования
 */
void ModelingModeBuilder::createModelingObjects(ModelingObjectsManager* modelingObjMgr)
{
        modelingObjMgr->addModelObject("Gear", new GearModelObject);
}

/*!
 * \brief addModelObject добавляет объект моделирования в таблицу объектов
 * \param modelObjectName наименование объекта моделирования
 * \param modelObject добавляемый объект моделирования
 */
void ModelingObjectsManager::addModelObject(const QString& modelObjectName, ModelObject *modelObject)
{
        modelObjects.insert(modelObjectName, modelObject); //здесь происходит SEGFAULT
}

The modelObjects field in the ModelingObjectsManager class is declared in the class as
QMap<QString, ModelObject*> modelObjects.
Using the debugger, I determined that the crash occurs in the detach method of the QMap class. Tried to declare modelObjects through the pointer, and the constructor ModelingObjectsManager wrote No result, the same error takes off. This code runs in a separate dll that is statically linked to the exe. I tried to insert the dll code into the exe's project, it also did not work, I thought that Qt had the same problem with containers as in STL from small software. I work in Windows 7 x64 Ultimate. Version Qt 5.5.0. CMake build system. Compiler from Visual Studio 2010. I tried to compile via MinGW (Qt 5.4.2), the same error occurs. How to bypass it?
modelObjects = new QMap<QString, ModelObjects*>().

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question