Index: ObjQt.pro ================================================================== --- ObjQt.pro +++ ObjQt.pro @@ -8,10 +8,11 @@ QtCore \ QtGui \ QtWidgets HEADERS += common/helpers.h \ + common/OFString+QString.h \ common/QtOwnershipManaging.h \ QtCore/QtChildEvent.h \ QtCore/QtCoreApplication.h \ QtCore/QtEvent.h \ QtCore/QtObject.h \ @@ -19,11 +20,12 @@ QtGui/QtGuiApplication.h \ QtGui/QtPaintDevice.h \ QtWidgets/QtApplication.h \ QtWidgets/QtWidget.h -SOURCES += QtCore/QtChildEvent.mm \ +SOURCES += common/OFString+QString.mm \ + QtCore/QtChildEvent.mm \ QtCore/QtCoreApplication.mm \ QtCore/QtEvent.mm \ QtCore/QtObject.mm \ QtCore/QtThread.mm \ QtGui/QtGuiApplication.mm \ ADDED common/OFString+QString.h Index: common/OFString+QString.h ================================================================== --- /dev/null +++ common/OFString+QString.h @@ -0,0 +1,9 @@ +#import + +#include + +@interface OFString (QString) ++ (instancetype)stringWithQString: (const QString&)qString; +- initWithQString: (const QString&)qString; +- (QString)qString; +@end ADDED common/OFString+QString.mm Index: common/OFString+QString.mm ================================================================== --- /dev/null +++ common/OFString+QString.mm @@ -0,0 +1,30 @@ +#import "OFString+QString.h" + +@implementation OFString (QString) ++ stringWithQString: (const QString&)qString +{ + return [[[self alloc] initWithQString: qString] autorelease]; +} + +- initWithQString: (const QString&)qString +{ + static_assert(sizeof(QChar) == sizeof(of_char16_t), + "QChar and of_char16_t have a different size!"); + + return [self initWithUTF16String: (of_char16_t*)qString.data() + length: qString.length()]; +} + +- (QString)qString +{ + static_assert(sizeof(of_char16_t) == sizeof(QChar), + "of_char16_t and QChar have a different size!"); + + void *pool = objc_autoreleasePoolPush(); + QString ret = QString((QChar*)[self UTF16String]); + + objc_autoreleasePoolPop(pool); + + return ret; +} +@end Index: common/helpers.h ================================================================== --- common/helpers.h +++ common/helpers.h @@ -2,20 +2,22 @@ #include #include #include +#import "OFString+QString.h" + static OF_INLINE OFString* toOF(const QString &qString) { - return [OFString stringWithUTF8String: qString.toUtf8()]; + return [OFString stringWithQString: qString]; } static OF_INLINE QString toQt(OFString *string) { - return QString::fromUtf8([string UTF8String]); + return [string qString]; } static OF_INLINE of_point_t toOF(const QPoint &qPoint) {