Bonsoir,
Je planche encore mon projet pour mon cours de programmation orienté objet. J'ai laissé de côté mon problème avec Phonon, parce que j'ai l'impression d'être dans une impasse; mais je vous rassure: ce dernier a droit à son post-it jaune fluo dédié, collé sur le mur blanc cassé qui est derrière l'écran de mon ordinateur.
Maintenant je m'attache à un autre point concernant mon projet: l'internationalisation. En effet, l'affichage de ma fenêtre est en français (pourquoi s'embêter à programmer ça, par exemple, en anglais alors qu'on est francophone de naissance?), mais mon professeur est allemand et j'étudie en Allemagne. Il faut donc que je traduise mon programme pour que son affichage soit dans la langue de Goethe.
J'avoue avoir batailler quelques temps (comprenez «quelques demi-heures») avec la commande tr("mon texte") et la macro QT_TRANSLATE_NOOP("maClasse", "mon texte"). Mais là n'est le problème. Mon projet-test (parce que je teste mon code dans un projet à part) refuse de charger la traduction que je lui demander de charger.
Voici le code pertinent:
- main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 #include "CustomApp.h" int main(int argc, char* argv[]) { CustomApp a(argc, argv, "Escriu! - Logs"); return a.exec(); }
- CustomApp.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 #ifndef CUSTOMAPP_H #define CUSTOMAPP_H #include <QApplication> #include <QDir> #include <QTranslator> #include "CustomMW.h" #include "TreeManager.h" class CustomApp : public QApplication { Q_OBJECT public: CustomApp(int argc, char** argv, QString appName = ""); ~CustomApp(); enum SystemType { MS_WINDOWS, MAC_OS, UNIX_LIKE, UNKNOWN }; QString getAppName(); void emitFirstSignal(); void setAppName(QString appName); signals: void appPathAnswerSource(QString path); void appMWConnectedSource(); void filesMultiMapAnswerSource(QMultiMap<QString,QString> filesMultiMap); void filesMultiMapUpdateSource(QMultiMap<QString,QString> filesMultiMap); void systemTypeAnswerSource(SystemType sT); //void connectionsDoneSource(); private: QString* m_appName; QString* m_appDir; CustomMW* m_mainWindow; SystemType m_systemType; TreeManager* m_treeManager; QTranslator* m_translator; void loadAppNameAndDir(); void loadConnections(); void loadMinimumAppDirTree(); private slots: void appPathAskSink(); void filesMultiMapAskSink(); void newFileSink(QString path, QString name); void systemTypeAskSink(); }; #endif // CUSTOMAPP_H
- CustomApp.cpp
Comme vous pouvez l'observer, la traduction se fait dans le constructeur de la classe CustomApp (cf. lignes 18 et 19 du fichier CustomApp.cpp). Après une séance de débogage, j'ai remarqué que la commande m_translator->load(...); me renvoie toujours la valeur true; c'est pourquoi je pense que la commande installTranslator(m_translator); est la coupable. En revanche, il est aussi possible que la commande lrelease de Qt Linguist ait cafouillée.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 #include "CustomApp.h" CustomApp::CustomApp(int argc, char** argv, QString appName) : QApplication (argc, argv) , m_appName (new QString(appName)) , m_appDir (new QString) , m_mainWindow (new CustomMW(appName)) , m_treeManager (new TreeManager(this)) , m_translator (new QTranslator) { m_mainWindow->setWindowTitle(appName); *m_appDir = QCoreApplication::applicationDirPath(); loadMinimumAppDirTree(); loadConnections(); emit appMWConnectedSource(); m_translator->load("EscriuLog_de", QCoreApplication::applicationDirPath() + "/ts"); installTranslator(m_translator); m_mainWindow->show(); } CustomApp::~CustomApp() { delete m_mainWindow; delete m_appName; delete m_appDir; delete m_treeManager; delete m_translator; } QString CustomApp::getAppName() { return *m_appName; } void CustomApp::emitFirstSignal() { //emit connectionsDoneSource(); } void CustomApp::loadConnections() { connect(m_mainWindow, SIGNAL(appPathAskSource()), this, SLOT(appPathAskSink())); connect(this, SIGNAL(appPathAnswerSource(QString)), m_mainWindow, SLOT(appPathAnswerSink(QString))); connect(m_mainWindow, SIGNAL(filesMultiMapAskSource()), this, SLOT(filesMultiMapAskSink())); connect(this, SIGNAL(filesMultiMapAnswerSource(QMultiMap<QString,QString>)), m_mainWindow, SLOT(filesMultiMapAnswerSink(QMultiMap<QString,QString>))); connect(m_mainWindow, SIGNAL(newFileSource(QString, QString)), this, SLOT(newFileSink(QString,QString))); connect(this, SIGNAL(filesMultiMapUpdateSource(QMultiMap<QString,QString>)), m_mainWindow, SLOT(filesMultiMapUpdateSink(QMultiMap<QString,QString>))); connect(this, SIGNAL(appMWConnectedSource()), m_mainWindow, SLOT(appMWConnectedSink())); } void CustomApp::loadMinimumAppDirTree() { //Directories m_treeManager->addPath(m_appDir); m_treeManager->addDir(m_appDir, "settings"); //Files } void CustomApp::appPathAskSink() { emit appPathAnswerSource(QCoreApplication::applicationDirPath()); } void CustomApp::filesMultiMapAskSink() { } void CustomApp::newFileSink(QString path, QString name) { } void CustomApp::systemTypeAskSink() { SystemType systemType; QString appDirPath = QCoreApplication::applicationDirPath(); if(appDirPath.left(1) == "/") systemType = UNIX_LIKE; else if(appDirPath.left(1) == ":") systemType = MAC_OS; else if((appDirPath.mid(1,2) == ":\\") || (appDirPath.mid(1,2) == ":/") || (appDirPath.left(2) == "\\\\")) systemType = MS_WINDOWS; else systemType = UNKNOWN; emit systemTypeAnswerSource(systemType); }
En tout cas, je vous demande votre aide parce que je ne parviens à me défaire ce bogue.
Merci d'avance pour votre aide.
PS: En pièce jointe je vous mets mon projet-test dans sa quasi-intégralité (j'ai nettoyé le projet et enlevé l'exécutable du dossier debug).
Partager