Closed lp35 closed 1 year ago
Thanks for your response.. In issue #16, I explained the reason why I didn't create a singletonclass:
I’ve been thinking about singleton when I created the library. I choose not to use it, because (in theory) you can use other fonts with this library. Also this current construct makes it possible to control exactly when the font is loaded. Also singletons are very limited, which prevents descent inheritance and specialization in subclasses. So that’s the reason I didn’t make a singleton :)
It's maybe over engineering, what about using CRTP? https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
Maybe you can just use your own singleton function in your application?
QtAwesome *qtAwesome()
{
static QtAwesome* qtAwesome = nullptr;
if( !qtAwesome ) {
qtAwesome = new QtAwesome();
qtAwesome->initFontAwesome();
}
return qtAwesome;
}
I would like to keep the QtAwesome library simple clean and lean. So adding templates for this reason is indeed over-engineering 😉
Why not adding this to mainstream? :) and changing the name of the function like QtAwesome* fa to enable quick access? It will not change the behaviour of your system. Otherwise yes, this is a good workaround. Thanks!
Don't add singleton. It may be an issue with dlls/etc... Unless u can wrap it around in macro so we can disable it. Thanks.
I will not add this Singleton. It's so trivial to implement and @Dariusz1989 it can indeed cause issues. I will close this feature request. Cheers!
Hi,
In your documentation, you said that QtAwesome should be initialized only once. In this case, why not creating a singleton class with static methods?
Thank you for this wonderful piece of code.
Edit: I can make a PR if you think it's a good idea.