Important: Please read the Qt Code of Conduct -

Can QObject::tr() be used in initialization of static const QString data members?

  • QUESTION: Is there a way to force the initialization of the QMetaObject data to avoid this crash in Qt5?

    Our large Qt4 application makes use of Object::tr() to initialize static const QString data members. This is crashing in Qt5 due to an uninitialized pointer.

    An abstract example:

    class MyClass {
            static const QString MyToolTipText;

    In CPP file:
        const QString MyClass::MyToolTipText (tr ("It's rude to point"));

    In Qt 5.5.1 on Windows, this CRASHES HERE, with m-> being NULL:

        static inline const char *objectClassName(const QMetaObject *m)
            return rawStringData(m, priv(m->>className);

    Our real stack looks like this, in Visual Studio 2010 (slightly cleaned up):

    • Qt5Cored.dll!objectClassName (const QMetaObject* m) Line 301
    • Qt5Cored.dll!QMetaObject::tr (const char* s, const char* c, int n) Line 365
    • riverware.exe!DbDmiEditDlg::DatasetModel::tr (const char* s, const char* c, int n)
    • riverware.exe!`dynamic initializer for 'DbDmiEditDlg::DatasetModel::EditTip''()
    • msvcr100d.dll!_initterm(void (void)* * pfbegin, void (void)* * pfend) Line 873
    • riverware.exe!__tmainCRTStartup()
    • riverware.exe!WinMainCRTStartup()
    • kernel32.dll!00000000777f59ed()
    • [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
    • ntdll.dll!0000000077a2c541()

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, QT_TR_NOOP is for that kind of use case

  • @SGaist ... thanks. Gosh though. This is a HUGE application, with many modules which get exercised only under special circumstances. (And since this only crashes when there is a call into the module, that approach will leave many time bombs in our code). Not to mention (well, I guess I will), that the macro QT_TR_NOOP is freaking ugly, way too heavy handed. Can we instead just insist that everyone who wants to use our system know English? (I'll check again with our director).

    Seriously though, I would really love to solve this problem CENTRALLY (with some Meta Object system initialization, if that's possible).

  • Lifetime Qt Champion

    Then I'd recommend bringing this to the interest mailing list. You'll find there Qt's developers/maintainers (this forum is more user oriented)

Log in to reply