Nothing to it!
Actually there is and the solutions maybe a little brittle.
Firstly, let's actually derive
class MyString: public QString { };
Secondly go and look in QString and copy all of the constructors out, you will need them.
Now you can add your code too.
String() : QString() { } // explicit String(const QString & value) : QString(value) { } explicit String(const QChar *unicode, int size = -1) : QString(unicode, size) { } String(QChar c) : QString(c) { } String(int size, QChar c) : QString(size, c) { } // this should pick up const char * surely tbh i need improvements here, my source code is utf8 for a start String(const char * _utf8) : QString(QLatin1String(_utf8)) { } inline String(QLatin1String latin1) : QString(latin1) { } inline String(const QString & _qstring) Q_DECL_NOTHROW : QString(_qstring) { } // might need these too. should be able to assign a QString to a String (should be easy) #if 0 QString &operator=(QChar c); QString &operator=(const QString &) Q_DECL_NOTHROW; inline QString &operator=(QLatin1String latin1); #endif #if 0 // might needs this #ifdef Q_COMPILER_RVALUE_REFS inline QString(QString && other) Q_DECL_NOTHROW : QString(other) { } // how the hell do you pass this on? inline QString &operator=(QString &&other) Q_DECL_NOTHROW { qSwap(d, other.d); return *this; } #endif #endif // default value or not? String(const QJsonValue & json) { // is this utter overkill in syntax terms. *((QString *) (this)) = json.toString(); } operator QJsonValue() const { return QJsonValue(*this); }
Does it work? Yes, but if QString's ctors change between revisions you'll need to update your derivation.