mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-22 14:18:09 +00:00
fix(app): avoid double free on shared singleton (qml/c++)
This commit is contained in:
parent
9e8b6b5930
commit
cc40beade1
4 changed files with 53 additions and 92 deletions
|
|
@ -56,7 +56,7 @@ if(NOT WIN32)
|
|||
endif()
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUSTOM_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG")
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Define packages, libs, sources, headers, resources and languages.
|
||||
|
|
|
|||
|
|
@ -99,9 +99,6 @@ void App::initContentApp () {
|
|||
CoreManager::init(this, m_parser.value("config"));
|
||||
qInfo() << "Activated selectors:" << QQmlFileSelector::get(&m_engine)->selector()->allSelectors();
|
||||
|
||||
// Avoid double free.
|
||||
m_engine.setObjectOwnership(this, QQmlEngine::CppOwnership);
|
||||
|
||||
// Provide `+custom` folders for custom components.
|
||||
{
|
||||
QQmlFileSelector *file_selector = new QQmlFileSelector(&m_engine);
|
||||
|
|
@ -243,8 +240,9 @@ QQuickWindow *App::getCallsWindow () {
|
|||
}
|
||||
|
||||
QQuickWindow *App::getMainWindow () const {
|
||||
QQmlApplicationEngine &engine = const_cast<QQmlApplicationEngine &>(m_engine);
|
||||
return qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
|
||||
return qobject_cast<QQuickWindow *>(
|
||||
const_cast<QQmlApplicationEngine *>(&m_engine)->rootObjects().at(0)
|
||||
);
|
||||
}
|
||||
|
||||
QQuickWindow *App::getSettingsWindow () {
|
||||
|
|
@ -273,9 +271,36 @@ bool App::hasFocus () const {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define REGISTER_EXISTING_SINGLETON(TYPE, NAME, METHOD) qmlRegisterSingletonType<TYPE>( \
|
||||
"Linphone", 1, 0, NAME, \
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{ \
|
||||
QObject *object = METHOD(); \
|
||||
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); \
|
||||
return object; \
|
||||
} \
|
||||
)
|
||||
|
||||
template<class T>
|
||||
void registerSingletonType (const char *name) {
|
||||
qmlRegisterSingletonType<T>(
|
||||
"Linphone", 1, 0, name,
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return new T();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void App::registerTypes () {
|
||||
qInfo() << "Registering types...";
|
||||
|
||||
qmlRegisterType<Camera>("Linphone", 1, 0, "Camera");
|
||||
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
|
||||
qmlRegisterType<ChatModel>("Linphone", 1, 0, "ChatModel");
|
||||
qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel");
|
||||
qmlRegisterType<SmartSearchBarModel>("Linphone", 1, 0, "SmartSearchBarModel");
|
||||
|
||||
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
|
||||
|
||||
qmlRegisterUncreatableType<CallModel>(
|
||||
"Linphone", 1, 0, "CallModel", "CallModel is uncreatable."
|
||||
);
|
||||
|
|
@ -289,85 +314,21 @@ void App::registerTypes () {
|
|||
"Linphone", 1, 0, "VcardModel", "VcardModel is uncreatable."
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<App>(
|
||||
"Linphone", 1, 0, "App",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return App::getInstance();
|
||||
}
|
||||
);
|
||||
registerSingletonType<AccountSettingsModel>("AccountSettingsModel");
|
||||
registerSingletonType<Presence>("Presence");
|
||||
registerSingletonType<PresenceStatusModel>("PresenceStatusModel");
|
||||
registerSingletonType<TimelineModel>("TimelineModel");
|
||||
|
||||
qmlRegisterSingletonType<CoreManager>(
|
||||
"Linphone", 1, 0, "CoreManager",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return CoreManager::getInstance();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<AccountSettingsModel>(
|
||||
"Linphone", 1, 0, "AccountSettingsModel",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return new AccountSettingsModel();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<CallsListModel>(
|
||||
"Linphone", 1, 0, "CallsListModel",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return CoreManager::getInstance()->getCallsListModel();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<ContactsListModel>(
|
||||
"Linphone", 1, 0, "ContactsListModel",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return CoreManager::getInstance()->getContactsListModel();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<Presence>(
|
||||
"Linphone", 1, 0, "Presence",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return new Presence();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<PresenceStatusModel>(
|
||||
"Linphone", 1, 0, "PresenceStatusModel",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return new PresenceStatusModel();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<SettingsModel>(
|
||||
"Linphone", 1, 0, "SettingsModel",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return CoreManager::getInstance()->getSettingsModel();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<SipAddressesModel>(
|
||||
"Linphone", 1, 0, "SipAddressesModel",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return CoreManager::getInstance()->getSipAddressesModel();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterSingletonType<TimelineModel>(
|
||||
"Linphone", 1, 0, "TimelineModel",
|
||||
[](QQmlEngine *, QJSEngine *) -> QObject *{
|
||||
return new TimelineModel();
|
||||
}
|
||||
);
|
||||
|
||||
qmlRegisterType<Camera>("Linphone", 1, 0, "Camera");
|
||||
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
|
||||
qmlRegisterType<ChatModel>("Linphone", 1, 0, "ChatModel");
|
||||
qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel");
|
||||
qmlRegisterType<SmartSearchBarModel>("Linphone", 1, 0, "SmartSearchBarModel");
|
||||
|
||||
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
|
||||
REGISTER_EXISTING_SINGLETON(App, "App", App::getInstance);
|
||||
REGISTER_EXISTING_SINGLETON(CoreManager, "CoreManager", CoreManager::getInstance);
|
||||
REGISTER_EXISTING_SINGLETON(SettingsModel, "SettingsModel", CoreManager::getInstance()->getSettingsModel);
|
||||
REGISTER_EXISTING_SINGLETON(SipAddressesModel, "SipAddressesModel", CoreManager::getInstance()->getSipAddressesModel);
|
||||
REGISTER_EXISTING_SINGLETON(CallsListModel, "CallsListModel", CoreManager::getInstance()->getCallsListModel);
|
||||
REGISTER_EXISTING_SINGLETON(ContactsListModel, "ContactsListModel", CoreManager::getInstance()->getContactsListModel);
|
||||
}
|
||||
|
||||
#undef REGISTER_EXISTING_SINGLETON
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void App::setTrayIcon () {
|
||||
|
|
|
|||
|
|
@ -89,15 +89,15 @@ private:
|
|||
}
|
||||
|
||||
QCommandLineParser m_parser;
|
||||
QQmlApplicationEngine m_engine;
|
||||
|
||||
DefaultTranslator *m_translator = nullptr;
|
||||
|
||||
Notifier *m_notifier = nullptr;
|
||||
|
||||
QVariantList m_available_locales;
|
||||
QString m_locale;
|
||||
|
||||
QQmlApplicationEngine m_engine;
|
||||
|
||||
DefaultTranslator *m_translator = nullptr;
|
||||
Notifier *m_notifier = nullptr;
|
||||
|
||||
QQuickWindow *m_calls_window = nullptr;
|
||||
QQuickWindow *m_settings_window = nullptr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ int main (int argc, char *argv[]) {
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Options to get a nice video render.
|
||||
#ifdef _WIN32
|
||||
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
|
||||
#else
|
||||
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
|
||||
#else
|
||||
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true);
|
||||
#endif // ifdef _WIN32
|
||||
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
|
||||
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue