madhukiranmp
31st December 2010, 09:01
Hi all,
I have created a simple application with a single combo box and some push buttons. This is to implement multilingual feature of Qt. I want to dynamically update the combo box if any new .qm file is added to the project folder. I'm getting the file name added to the combo box. But once I select the dynamically added item in the combo box the language changes and the corresponding new item disappears. I want it to be added permanently. please help how to do this.
Thanks in advance.
here is the code I've used
#include "detect.h"
#include "ui_detect.h"
#include "QFileSystemWatcher"
#include "QFileInfo"
#include "QTranslator"
#include "QTextStream"
#include "QString"
#include "QComboBox"
QTranslator langTranslator;
QString line1;
detect::detect(QWidget *parent) :
QDialog(parent),
ui(new Ui::detect)
{
ui->setupUi(this);
qApp->installTranslator(&langTranslator);
system("ls ..\ >new.txt");
system("comm -13 old.txt new.txt >difference.txt");
readdifference();
QFileSystemWatcher *watcher;
watcher=new QFileSystemWatcher;
watcher->addPath("C:/Documents and Settings/20010833/My Documents/testdet");
QObject::connect(watcher, SIGNAL(directoryChanged(const QString)),this, SLOT(directorychanged(const QString)));
}
detect::~detect()
{
delete ui;
}
void detect::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void detect::on_comboBox_activated(const QString & text)
{
if(text == tr("French"))
{
langTranslator.load("arrowpad_fr","C:/Documents and Settings/20010833/Desktop/testdet" );
}
else if(text == line1)
{
langTranslator.load(line1,"C:/Documents and Settings/20010833/Desktop/testdet" );
}
}
void detect::readdifference()
{
QString path="C:/Documents and Settings/20010833/Desktop/testdet";
QFile nfile("difference.txt");
if(!nfile.open(QIODevice::ReadOnly ))
return;
QTextStream in(& nfile);
while(!in.atEnd())
{
line1=in.readLine();
if(line1.endsWith("qm"))
{
ui->comboBox->addItem(line1,QVariant::Char);
// break;
}
}
}
I have created a simple application with a single combo box and some push buttons. This is to implement multilingual feature of Qt. I want to dynamically update the combo box if any new .qm file is added to the project folder. I'm getting the file name added to the combo box. But once I select the dynamically added item in the combo box the language changes and the corresponding new item disappears. I want it to be added permanently. please help how to do this.
Thanks in advance.
here is the code I've used
#include "detect.h"
#include "ui_detect.h"
#include "QFileSystemWatcher"
#include "QFileInfo"
#include "QTranslator"
#include "QTextStream"
#include "QString"
#include "QComboBox"
QTranslator langTranslator;
QString line1;
detect::detect(QWidget *parent) :
QDialog(parent),
ui(new Ui::detect)
{
ui->setupUi(this);
qApp->installTranslator(&langTranslator);
system("ls ..\ >new.txt");
system("comm -13 old.txt new.txt >difference.txt");
readdifference();
QFileSystemWatcher *watcher;
watcher=new QFileSystemWatcher;
watcher->addPath("C:/Documents and Settings/20010833/My Documents/testdet");
QObject::connect(watcher, SIGNAL(directoryChanged(const QString)),this, SLOT(directorychanged(const QString)));
}
detect::~detect()
{
delete ui;
}
void detect::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void detect::on_comboBox_activated(const QString & text)
{
if(text == tr("French"))
{
langTranslator.load("arrowpad_fr","C:/Documents and Settings/20010833/Desktop/testdet" );
}
else if(text == line1)
{
langTranslator.load(line1,"C:/Documents and Settings/20010833/Desktop/testdet" );
}
}
void detect::readdifference()
{
QString path="C:/Documents and Settings/20010833/Desktop/testdet";
QFile nfile("difference.txt");
if(!nfile.open(QIODevice::ReadOnly ))
return;
QTextStream in(& nfile);
while(!in.atEnd())
{
line1=in.readLine();
if(line1.endsWith("qm"))
{
ui->comboBox->addItem(line1,QVariant::Char);
// break;
}
}
}