QT6和类特异性操作员的编译问题新
考虑一个具有自定义操作员新的课程。
class BaseClass {
void* operator new(size_t size);
void operator delete(void* p);
};
class MyClass : public BaseClass {
public:
MyClass(int);
};
然后使用myClass
作为信号的参数和QT中的
qt5 slot,但使用QT6使用QT6在使用Visual Studio 2019时在qmetatype中生成深度的汇编错误,而无法找到特定于类的类别myClass
的新位置。
vs 2019的汇编错误(更改为隐藏特定路径和类名称):
...QtCore\qmetatype.h(2313): error C2660: 'BaseClass::operator new': function does not take 3 arguments
: note: see declaration of 'BaseClass::operator new'
...QtCore\qmetatype.h(2310): note: while compiling class template member function 'QtPrivate::QMetaTypeInterface::CopyCtrFn QtPrivate::QMetaTypeForType<T>::getCopyCtr(void)'
with
[
T=Ty
]
...QtCore\qmetatype.h(2370): note: see reference to class template instantiation 'QtPrivate::QMetaTypeForType<T>' being compiled
with
[
T=Ty
]
...QtCore\qmetatype.h(2494): note: see reference to class template instantiation 'QtPrivate::QMetaTypeInterfaceWrapper<Ty>' being compiled
...QtCore\qmetatype.h(2537): note: see reference to function template instantiation 'const QtPrivate::QMetaTypeInterface *QtPrivate::qTryMetaTypeInterfaceForType<Unique,QtPrivate::TypeAndForceComplete<MyClass &,std::false_type>>(void)' being compiled
with
[
Unique=qt_meta_stringdata_..._t
]
moc_xxx.cpp(286): note: see reference to variable template 'const QtPrivate::QMetaTypeInterface *const qt_incomplete_metaTypeArray<qt_meta_stringdata_ModelBrowser_t,QtPrivate::TypeAndForceComplete<ModelBrowser,std::integral_constant<bool,1> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<MyClass &,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<MyClass &,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,...[58]' being compiled
尝试添加通用类特定的位置新(也就是void* operator* operator new new(size_t size,std :: align_val_t,void*),void*))似乎可能是可能的,但根据标准和其他编译器中的失败而不是。
Consider a class with custom operator new.
class BaseClass {
void* operator new(size_t size);
void operator delete(void* p);
};
class MyClass : public BaseClass {
public:
MyClass(int);
};
And then using MyClass
as an argument for a signal and slot in Qt
With Qt5 that works, but with Qt6 that generates compilation errors deep in QMetaType when using Visual Studio 2019, by failing to find a class-specific placement new for MyClass
.
Compilation error with VS 2019 (changed to hide specific paths and class-names):
...QtCore\qmetatype.h(2313): error C2660: 'BaseClass::operator new': function does not take 3 arguments
: note: see declaration of 'BaseClass::operator new'
...QtCore\qmetatype.h(2310): note: while compiling class template member function 'QtPrivate::QMetaTypeInterface::CopyCtrFn QtPrivate::QMetaTypeForType<T>::getCopyCtr(void)'
with
[
T=Ty
]
...QtCore\qmetatype.h(2370): note: see reference to class template instantiation 'QtPrivate::QMetaTypeForType<T>' being compiled
with
[
T=Ty
]
...QtCore\qmetatype.h(2494): note: see reference to class template instantiation 'QtPrivate::QMetaTypeInterfaceWrapper<Ty>' being compiled
...QtCore\qmetatype.h(2537): note: see reference to function template instantiation 'const QtPrivate::QMetaTypeInterface *QtPrivate::qTryMetaTypeInterfaceForType<Unique,QtPrivate::TypeAndForceComplete<MyClass &,std::false_type>>(void)' being compiled
with
[
Unique=qt_meta_stringdata_..._t
]
moc_xxx.cpp(286): note: see reference to variable template 'const QtPrivate::QMetaTypeInterface *const qt_incomplete_metaTypeArray<qt_meta_stringdata_ModelBrowser_t,QtPrivate::TypeAndForceComplete<ModelBrowser,std::integral_constant<bool,1> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<MyClass &,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<MyClass &,std::integral_constant<bool,0> >,QtPrivate::TypeAndForceComplete<void,std::integral_constant<bool,0> >,...[58]' being compiled
Trying to add generic class-specific placement new (that is void* operator new(size_t size, std::align_val_t, void*)
) seem possible for VS 2019, but not according to the standard and fails in other compilers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下只是一个解决方案,它并不总是有效 - 但这很琐碎:
其起作用的原因是Qmetatype通过
std :: IS_DEFAULT_CONSTRUCTIBLE_V
和std守护了有问题的调用:: is_copy_constructible_v
。The following is just a work-around, and it does not always work - but it is trivial:
The reason it works is that QMetaType has guarded the problematic calls by
std::is_default_constructible_v
andstd::is_copy_constructible_v
.