Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can QObject::tr() be used in initialization of static const QString data members?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Phil_W
    wrote on 4 Nov 2015, 21:56 last edited by Phil_W 11 Apr 2015, 22:27
    #1

    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 {
        Q_OBJECT
        private:
            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->d.data being NULL:

        static inline const char *objectClassName(const QMetaObject *m)
        {
            return rawStringData(m, priv(m->d.data)->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()
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Nov 2015, 22:02 last edited by
      #2

      Hi and welcome to devnet,

      AFAIK, QT_TR_NOOP is for that kind of use case

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply 4 Nov 2015, 22:23
      0
      • S SGaist
        4 Nov 2015, 22:02

        Hi and welcome to devnet,

        AFAIK, QT_TR_NOOP is for that kind of use case

        P Offline
        P Offline
        Phil_W
        wrote on 4 Nov 2015, 22:23 last edited by
        #3

        @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).

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Nov 2015, 22:27 last edited by
          #4

          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)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          4 Nov 2015, 21:56

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved