QCoreApplication::translate() versus QObject::tr() versus tr()
Solved
General and Desktop
-
Up to now I have used tr() macro for translatable string in classes that derived from QObject and used the QOBJECT macro. For non QObject code I have used QCoreApplication::translate() specifying a "context".
I just now encountered code that uses QObject::tr() - does that effectively do the same as QCoreApplication::translate with a context of "QObject"?
Thanks
David -
does that effectively do the same as QCoreApplication::translate with a context of "QObject"?
Yes.
Q_OBJECT
macro adds a statictr
function to the class that just callsQMetaObject::tr
from the staticMetaObject of that class and that callsQCoreApplication::translate()
with the class name as the context, so calling staticQObject::tr
will have a context of "QObject".