Reviewing merge request #753: Simplified more convenient singleton pattern for MComponentData by Thierry Basti an.
Helps to get e.g. Haptics integrated for plain Qt apps.
Commits that would be merged:
Version 1
- 358efd1
- 1d0bb4b
Changes: Simplified more convenient singleton pattern for MComponentData by Thierry Bastian.
Showing
358efd1-1d0bb4bComments
Proper singletons have a private constructor.
Who owns the MComponentData? Both it’s instance()-method and MApplicationPrivate::init() create new objects… We abort if someone calls MComponentData->instance() and after that tries to create an MApplication. We also abort if someone tries to create several MApplications:
testX()
{
MApplication app(1, "test1");
...
}
main()
{
test1();
test2();
....
}
+ Q_ASSERT_X(QCoreApplication::instance(), "MComponentData", "A QApplication should have been created."); + Q_ASSERT_X(!qobject_cast<MApplication*>(QCoreApplication::instance()), "MComponentData", "A MApplication is found but the MComponentData was not created.");
Q_ASSERT is not compiled when doing a release build, so this will just segfault on the device if the assertion doesn’t hold.


Add a new comment:
Login or create an account to post a comment