Hello everyone; I'm new at the forum, and I need some help with translations.
I've made a minimal application for testing translations before going on production, and I realised that its not working. I did it as some tuts said and using c++ qt programming guide as guideline, but I'm still getting the error "instantiate QApplication object first" and what is most strange is that im only seen it (the message) when debugging with gdb. Of course translations are not working, and the text appears in its original language (spanish).
Im running on windows xp with mingw, qt4.5.1. I haven't tested it in Linux yet but from now on I've not had problems with this (linux windows, windows linux)
Here is my code:
int main(int argc, char *argv[]){
theLabel->setText(*trstring);
if(!mainWindow->centralWidget())
mainWindow
->setCentralWidget
(new QWidget(0));
theGridLayout->addWidget(theLabel, 0, 0, Qt::AlignLeft);
mainWindow->centralWidget()->setLayout(theGridLayout);
if(!theTranslator.
load("englishTranslations",
QDir::currentPath()+"/translations")) exit(0);
myApp->installTranslator(&theTranslator);
mainWindow->show();
return (myApp->exec());
}
int main(int argc, char *argv[]){
QApplication *myApp = new QApplication(argc, argv, true);
QWidget *mainWindow;
QString *trstring;
QLabel *theLabel;
QGridLayout *theGridLayout;
QTranslator theTranslator;
theGridLayout = new QGridLayout(0);
trstring = new QString(QApplication::tr("Hola"));
theLabel = new QLabel(0);
theLabel->setText(*trstring);
if(!mainWindow->centralWidget())
mainWindow->setCentralWidget(new QWidget(0));
theGridLayout->addWidget(theLabel, 0, 0, Qt::AlignLeft);
mainWindow->centralWidget()->setLayout(theGridLayout);
if(!theTranslator.load("englishTranslations", QDir::currentPath()+"/translations"))
exit(0);
myApp->installTranslator(&theTranslator);
mainWindow->show();
return (myApp->exec());
}
To copy to clipboard, switch view to plain text mode
I don't know why is it failling, I've added the TRANSLATIONS line to the .pro file, and I've done the lupdate and lrelease execution with success. And later the translation with the liguist utility.
What I'm missing ? What could be wrong ? Is it so difficult ? Everyone seems to be doing it as something quite simple....
Thanks, regards
Nahuel
Bookmarks