PDA

View Full Version : qInitResources_mimetypes() crashes



ComServant
1st April 2013, 21:31
For several months and several versions of Qt, I've been on-and-off crashing in qInitResources_mimetypes() before the code even reaches main().

Here's the callstack:

0 (anonymous namespace)::qInitResources_mimetypes_ctor_class_:: qInitResources_mimetypes_ctor_class_ qrc_mimetypes.cpp 15851 0x6b9ea223
1 __static_initialization_and_destruction_0 qrc_mimetypes.cpp 15851 0x6b9ea2a9
2 _GLOBAL__sub_I__Z24qInitResources_mimetypesv qrc_mimetypes.cpp 15860 0x6b9ea2db
3 __do_global_ctors C:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib\Qt5Cored.dll 0x6b9f2bfa
4 ?? 0x2
5 ?? 0x22fd24
6 ??

Why does this occur and how can I work around it?

Currently I'm using Qt 5.0.1, but have had the same problem with 5.0.0 and 4.8. Any ideas?

Vekman
15th May 2014, 14:24
I am having the same problem, I dont know what I should do to fix it, did you manage to find a solution or workaround?

ComServant
16th May 2014, 21:36
I don't remember if this was the same problem or not, but if so, the problem occurs because your resources are attached to a static library, and C++'s order of static initialization is undefined, so weird crashes can occur on occasion.

The solution is that, for static libraries, you manually initialize your resource packs. See [here] (http://qt-project.org/doc/qt-4.8/resources.html).

I do it by explicitly calling:

Q_INIT_RESOURCE(EditorResources); //EditorResources.qrc is the name of the resource package, but you drop the '.qrc'

However, I also ran into another problem: You can't call Q_INIT_RESOURCE() from inside a namespace (I guess it messes up some macro or something).

So I had to do it like this:

//This function is because Q_INIT_RESOURCE() is required to be called from a plain function not in any namespace.
//That macro needs to be called to initialize Qt Resource archives when in dynamic or static libraries.
void InitializeQtResources()
{
Q_INIT_RESOURCE(EditorResources);
}

namespace Platform
{
MainWindow::MainWindow(int argc, char *argv[])
: ui(new Ui::MainWindow)
{
//Initialize all the images we have baked into the static library in Qt resource packages.
InitializeQtResources();

//Initialize the widgets that are children of this widget.
ui->setupUi(this);

this->initializeMyWidgets();
}

} //End of namespace.

That was quite a while ago, so I don't know if the problem I was having in this thread is the same or a different problem.