Hi.
I have a BIG problem using QTranslator in qtjambi on czech winxp.
I couldn't find a problem for as long as one day and now I am totally lost.
I created a qtjambi gui app ( 3 or 4 window next-next wizard ), initialized
translator
and started QApplication.exec().
My problem is that QTranslator is working only "sometimes". I can't describe
you, when it stops working,
but i saw the change ( when tracing code by debugger ) on creating QIcon from
png in "resources", but too when
creating an QMenu(), initializing log4j etc...
To describe the problem, imagine, that my translation qm file contains czech
translation from "BAD" to "GOOD".
Here is flow of my code:
*1 but remember, that this code -as-is- will not show the problem. I've tried
to create a test prototype,
but it works without problems. Problem lies only in my app, doing some other (
but no qt-centric ) stuff.
class Foo() {
// i have debugging method to see if translator is working
public static void foo() { System.out.println ( QApplication.translate
( "mysection", "foo" );
}
class MainClass {
// translator is a member of main class, it couldn't be garbage collected
private QTranslator translator;
// called from main()
public void runApp() {
// i'll use Foo.foo() to see translator output.
Foo.foo(); // 1
initLocales();
Foo.foo(); // 2
initLogging();
Foo.foo(); // 3
initSsl();
Foo.foo(); // 4
initSomethingOther();
Foo.foo(); // 5
// create and show tray icon
MyTrayIcon tray = new MyTrayIcon();
tray.show();
// exec app
QApplication.exec();
}
// this is my system tray icon
public class MyTrayIcon extends QSystemTrayIcon {
public Signal0 signalForcedCheck = new Signal0();
private QMenu tray_menu;
private QAction action_exit;
private QAction action_force_check;
public MyTrayIcon() throws IOException {
Foo.foo(); // 6
QIcon i = new QIcon ( "classpath:///META-INF/blablabla/tray.png" );
// *1
Foo.foo(); // 7
this.setIcon(i);
// *1
Foo.foo(); // 8
QMenu m = new QMenu();
Foo.foo(); // 9
// this initialize a translator
void initLocales() {
this.translator = new QTranslator();
// i am loading qm into memory to be sure there isn't problem with
"resource lost"
InputStream is =
MainModule.class.getResourceAsStream("/META-INF/main/resources/translations/app.qm");
byte[] ts = org.apache.commons.io.IOUtils.toByteArray(is);
System.out.println(ts.length); // shows valid file length
translator.load(ts); // load
QApplication.installTranslator(translator); // install
}
}
Now I have a code, which should 1 time prints "BAD" ( translator uninitialized
) and 8 times prints "GOOD".
But output looks like:
1 BAD // this is ok
2 GOOD
3 GOOD
4 GOOD
5 GOOD
6 GOOD // QIcon is going to be constructed
7 BAD
8 BAD
9 BAD
When I comment lines marked with *1 ( QIcon ), then output looks:
1 BAD // this is ok
2 GOOD
3 GOOD
4 GOOD
5 GOOD
6 GOOD
7 GOOD
8 GOOD // QMenu is going to be constructed
9 BAD
But as I said, I saw:
1 BAD // this is ok
2 GOOD // going to initialize log4j
3 BAD
4 BAD
5 BAD
6 BAD
7 BAD
8 BAD
9 BAD
Sometimes my application is translated in 2 or 3 wizzard windows and last window
is untranslated, etc. It looks like QTranslator "disappear" ...
Where (the f*ck) is the problem, please? Should it be a bug in QTranslator?
What about garbage
collector? I see that MainClass.translator shouldn't be gc-ed, but it seems
like it is.
How to deal with this? I've tried to create my own class extending from
QTranslator and print something on
finalize(), but it is protected final, so I can't to do so.
Any other idea how to find a problem?
Thank you.
--
Dusan
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest