implementing tr() results in exception?
-
Today I've been through a project replacing instances of "some text" with tr("some text"), the project builds with no warnings and no errors, however when I launch in the debugger I get an exception instantly:
Debugger encountered an exception: Exception at 0x6a432132, code: 0xc0000005: read access at 0x0, flags0x0 (first chance)
Execution is halted on Q_OBJECT below:
class SendRDF : public QMainWindow { Q_OBJECT
No other changes have been performed.
-
@jsulm , Yes, that was the first thing I tried, I'm reading through:
https://doc.qt.io/qt-5/i18n-source-translation.htmlNot sure if I have jumped the gun in building before the implementation is complete? I just tried to include:
Q_DECLARE_TR_FUNCTIONS(SendRDF)
It has a red underline, not sure if its available in Qt 5.9.2 ?
In the class where the exception is raised there two statics initialisated:
QString SendRDF::msstrAbort(tr("&Abort")); QString SendRDF::msstrTransferComplete(tr("&Transfer Complete"));
Could this be the cause?
@SPlatten said in implementing tr() results in exception?:
In the class where the exception is raised there two statics initialisated:
Could this be the cause?Yes, this is probably the error source.
This is will done before Q(Core|Gui)Application has been initialized, so there is not translator available.
You cannot do this like this, you have to initialize the static members after QApplication has been initialized. -
Today I've been through a project replacing instances of "some text" with tr("some text"), the project builds with no warnings and no errors, however when I launch in the debugger I get an exception instantly:
Debugger encountered an exception: Exception at 0x6a432132, code: 0xc0000005: read access at 0x0, flags0x0 (first chance)
Execution is halted on Q_OBJECT below:
class SendRDF : public QMainWindow { Q_OBJECT
No other changes have been performed.
-
@jsulm , Yes, that was the first thing I tried, I'm reading through:
https://doc.qt.io/qt-5/i18n-source-translation.htmlNot sure if I have jumped the gun in building before the implementation is complete? I just tried to include:
Q_DECLARE_TR_FUNCTIONS(SendRDF)
It has a red underline, not sure if its available in Qt 5.9.2 ?
In the class where the exception is raised there two statics initialisated:
QString SendRDF::msstrAbort(tr("&Abort")); QString SendRDF::msstrTransferComplete(tr("&Transfer Complete"));
Could this be the cause?
-
@jsulm , Yes, that was the first thing I tried, I'm reading through:
https://doc.qt.io/qt-5/i18n-source-translation.htmlNot sure if I have jumped the gun in building before the implementation is complete? I just tried to include:
Q_DECLARE_TR_FUNCTIONS(SendRDF)
It has a red underline, not sure if its available in Qt 5.9.2 ?
In the class where the exception is raised there two statics initialisated:
QString SendRDF::msstrAbort(tr("&Abort")); QString SendRDF::msstrTransferComplete(tr("&Transfer Complete"));
Could this be the cause?
@SPlatten said in implementing tr() results in exception?:
not sure if its available in Qt 5.9.2 ?
The compiler would break with an error if the macro would not be defined.
-
@jsulm , Yes, that was the first thing I tried, I'm reading through:
https://doc.qt.io/qt-5/i18n-source-translation.htmlNot sure if I have jumped the gun in building before the implementation is complete? I just tried to include:
Q_DECLARE_TR_FUNCTIONS(SendRDF)
It has a red underline, not sure if its available in Qt 5.9.2 ?
In the class where the exception is raised there two statics initialisated:
QString SendRDF::msstrAbort(tr("&Abort")); QString SendRDF::msstrTransferComplete(tr("&Transfer Complete"));
Could this be the cause?
-
@SPlatten said in implementing tr() results in exception?:
not sure if its available in Qt 5.9.2 ?
The compiler would break with an error if the macro would not be defined.
-
@SPlatten said in implementing tr() results in exception?:
Q_DECLARE_TR_FUNCTIONS(SendRDF)
Why do you use this?
SendRDF::tr()
should be enough.@KroMignon , I don't it was something I was investigating after getting the error and reading the documentation.
-
@jsulm , Yes, that was the first thing I tried, I'm reading through:
https://doc.qt.io/qt-5/i18n-source-translation.htmlNot sure if I have jumped the gun in building before the implementation is complete? I just tried to include:
Q_DECLARE_TR_FUNCTIONS(SendRDF)
It has a red underline, not sure if its available in Qt 5.9.2 ?
In the class where the exception is raised there two statics initialisated:
QString SendRDF::msstrAbort(tr("&Abort")); QString SendRDF::msstrTransferComplete(tr("&Transfer Complete"));
Could this be the cause?
@SPlatten said in implementing tr() results in exception?:
In the class where the exception is raised there two statics initialisated:
Could this be the cause?Yes, this is probably the error source.
This is will done before Q(Core|Gui)Application has been initialized, so there is not translator available.
You cannot do this like this, you have to initialize the static members after QApplication has been initialized. -
@SPlatten said in implementing tr() results in exception?:
In the class where the exception is raised there two statics initialisated:
Could this be the cause?Yes, this is probably the error source.
This is will done before Q(Core|Gui)Application has been initialized, so there is not translator available.
You cannot do this like this, you have to initialize the static members after QApplication has been initialized.@KroMignon , thank you, that makes sense.