fix: core dumped under Qt 6.4

call method metaObject of QMetaType will coredump under Qt 6.4

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2023-08-28 11:11:50 +08:00 committed by black-desk
parent 25a7acb6fd
commit 8a662314f2
7 changed files with 30 additions and 13 deletions

View File

@ -26,6 +26,7 @@ void registerComplexDbusType()
qDBusRegisterMetaType<QMap<QString, QString>>();
qRegisterMetaType<PropMap>();
qDBusRegisterMetaType<PropMap>();
qDBusRegisterMetaType<QDBusObjectPath>();
}
} // namespace

View File

@ -35,4 +35,11 @@ constexpr auto ApplicationManagerDestDBusName =
u8"deepin_application_manager_dest_bus";
#endif
constexpr auto ObjectManagerInterface = "org.desktopspec.DBus.ObjectManager";
constexpr auto JobManagerInterface = "org.desktopspec.JobManager1";
constexpr auto JobInterface = "org.desktopspec.JobManager1.Job";
constexpr auto ApplicationManagerInterface = "org.desktopspec.ApplicationManager1";
constexpr auto InstanceInterface = "org.desktopspec.ApplicationManager1.Instance";
constexpr auto ApplicationInterface = "org.desktopspec.ApplicationManager1.Application";
#endif

View File

@ -28,8 +28,7 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr<Identifie
std::terminate();
}
if (!registerObjectToDBus(
this, DDEApplicationManager1ObjectPath, getDBusInterface(QMetaType::fromType<ApplicationManager1Adaptor>()))) {
if (!registerObjectToDBus(this, DDEApplicationManager1ObjectPath, ApplicationManagerInterface)) {
std::terminate();
}
@ -130,8 +129,7 @@ bool ApplicationManager1Service::addApplication(DesktopFile desktopFileSource) n
return false;
}
if (!registerObjectToDBus(
ptr, application->applicationPath().path(), getDBusInterface(QMetaType::fromType<ApplicationAdaptor>()))) {
if (!registerObjectToDBus(ptr, application->applicationPath().path(), ApplicationInterface)) {
return false;
}
m_applicationList.insert(application->applicationPath(), application);

View File

@ -317,7 +317,7 @@ bool ApplicationService::addOneInstance(const QString &instanceId, const QString
auto *adaptor = new InstanceAdaptor(service);
QString objectPath{m_applicationPath.path() + "/" + instanceId};
if (registerObjectToDBus(service, objectPath, getDBusInterface(QMetaType::fromType<InstanceAdaptor>()))) {
if (registerObjectToDBus(service, objectPath, InstanceInterface)) {
m_Instances.insert(QDBusObjectPath{objectPath}, QSharedPointer<InstanceService>{service});
service->moveToThread(this->thread());
adaptor->moveToThread(this->thread());

View File

@ -9,8 +9,7 @@ JobManager1Service::JobManager1Service(ApplicationManager1Service *parent)
: m_parent(parent)
{
new JobManager1Adaptor{this};
if (!registerObjectToDBus(
this, DDEApplicationManager1JobManagerObjectPath, getDBusInterface(QMetaType::fromType<JobManager1Adaptor>()))) {
if (!registerObjectToDBus(this, DDEApplicationManager1JobManagerObjectPath, JobManagerInterface)) {
std::terminate();
}
qRegisterMetaType<LaunchTask>();

View File

@ -61,7 +61,7 @@ public:
auto *ptr = job.data();
new JobAdaptor(ptr);
if (!registerObjectToDBus(ptr, objectPath, getDBusInterface(QMetaType::fromType<JobAdaptor>()))) {
if (!registerObjectToDBus(ptr, objectPath, JobInterface)) {
qCritical() << "can't register job to dbus.";
future.cancel();
return {};

View File

@ -196,12 +196,24 @@ void unregisterObjectFromDBus(const QString &path);
inline QString getDBusInterface(const QMetaType &meta)
{
const auto *infoObject = meta.metaObject();
if (auto infoIndex = infoObject->indexOfClassInfo("D-Bus Interface"); infoIndex != -1) {
return infoObject->classInfo(infoIndex).value();
auto name = QString{meta.name()};
if (name == "ApplicationAdaptor") {
return ApplicationInterface;
}
qWarning() << "no interface found.";
return {};
if (name == "InstanceAdaptor") {
return InstanceInterface;
}
if (name == "APPObjectManagerAdaptor" or name == "AMObjectManagerAdaptor") {
return ObjectManagerInterface;
}
// const auto *infoObject = meta.metaObject();
// if (auto infoIndex = infoObject->indexOfClassInfo("D-Bus Interface"); infoIndex != -1) {
// return infoObject->classInfo(infoIndex).value();
// }
qWarning() << "couldn't found interface:" << name;
return "";
}
inline ObjectInterfaceMap getChildInterfacesAndPropertiesFromObject(QObject *o)