Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.2.2
-
None
-
-
89e26cb467 (qt/tqtc-qtbase/6.2)
Description
Locate "qtbase/src/gui/painting/qcoregraphics_p.h" and you will find an objective-c category for Apples NSImage
// -------------------------------------
@interface NSImage (QtExtras)
+ (instancetype)imageFromQImage:(const QT_PREPEND_NAMESPACE(QImage) &)image;
// -------------------------------------
Now imagine you have two plug-ins compiled with Qt. Let's say with plug_a with Qt 5.15 and plug_b Qt 6.2. When plug_b with Qt 6.2 itself calls ...
[NSImage imageFromQImage:myImage];
... it is not clear which Qt library (5.15 or 6.2) will be used.
Apple warns about those problems
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html
---> "If the name of a method declared in a category is the same as a method in the original class, or a method in another category on the same class (or even a superclass), the behavior is undefined as to which method implementation is used at runtime. "
We have some crashes with that current situations. At the moment we use the following workaround which is based on namespaces.
// -------------------------------------
#define QtExtras QT_MANGLE_NAMESPACE(QtExtras)
#define imageFromQImage QT_MANGLE_NAMESPACE(imageFromQImage)
#define imageFromQIcon QT_MANGLE_NAMESPACE(imageFromQIcon)
@interface NSImage (QtExtras)
+ (instancetype)QT_MANGLE_NAMESPACE (imageFromQImage):(const QT_PREPEND_NAMESPACE(QImage) &)image;
+ (instancetype)imageFromQIcon:(const QT_PREPEND_NAMESPACE(QIcon) &)icon;
+ (instancetype)imageFromQIcon:(const QT_PREPEND_NAMESPACE(QIcon) &)icon withSize:(int)size;
// -------------------------------------
FYI : vestbo
Attachments
Issue Links
- relates to
-
QTBUG-119338 Objective-C usage can result in undefined behavior (part 2)
-
- Closed
-
For Gerrit Dashboard: QTBUG-100059 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
408984,3 | Namespace a few missing Objective-C categories and their methods | dev | qt/qtbase | Status: MERGED | +2 | 0 |
409035,2 | Namespace a few missing Objective-C categories and their methods | 6.3 | qt/qtbase | Status: MERGED | +2 | 0 |
409059,2 | Namespace a few missing Objective-C categories and their methods | tqtc/lts-6.2 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |