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].
I do it by explicitly calling:
Q_INIT_RESOURCE(EditorResources); //EditorResources.qrc is the name of the resource package, but you drop the '.qrc'
Q_INIT_RESOURCE(EditorResources); //EditorResources.qrc is the name of the resource package, but you drop the '.qrc'
To copy to clipboard, switch view to plain text mode
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.
//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.
To copy to clipboard, switch view to plain text mode
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.
Bookmarks