http://wiki.qtcentre.org/index.php?titl ... OSX_Finder
Die int main sieht dann sehr armselig aus nur ein paar zeile ....
Code: Alles auswählen
#include "main.moc"
int main(int argc, char *argv[]) {
OS_application a( argc, argv );
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( CleanProcess() ) );
return a.exec();
}
Code: Alles auswählen
#define osApplication \
(static_cast<OS_application*>(QCoreApplication::instance()))
class OS_application : public QApplication
{
Q_OBJECT
//
public:
OS_application( int &argc, char **argv )
: QApplication(argc, argv)
{
/* QSetting setup */
setOrganizationName(_ORGANIZATION_NAME_);
setOrganizationDomain(_PROGRAM_NAME_DOMAINE_);
setApplicationName(_PROGRAM_NAME_);
#if defined Q_WS_MAC
QStringList path;
path.append(QApplication::applicationDirPath());
QDir dir(QApplication::applicationDirPath());
dir.cdUp();
path.append(dir.absolutePath());
dir.cdUp();
path.append(dir.absolutePath());
QApplication::setLibraryPaths(path);
QDir::setCurrent(dir.absolutePath()); /* here down -> bunde top */
#endif
#if defined Q_WS_X11
QDir::setCurrent(QDir::homePath());
#endif
Load_Language(UserLanguage()); /* sistem sprache laden! */
#if defined Q_WS_WIN
setStyle(new QtDotNetStyle);
#endif
QDesktopWidget *desk = QApplication::desktop();
if (desk->screenGeometry().height() > 601) {
Load_New_Gmain(false);
} else {
QMessageBox::information(0, tr("Desktop Geometry"),tr("Please set your Screen height more as %1.").arg(desk->screenGeometry().height()));
}
}
das erste mal lade ich den QMainWindow durch Load_New_Gmain(false);
false da noch keine instanz vorhanden ist von andere alte QMainWindow
das laden geht dann einfach :
Code: Alles auswählen
void Load_New_Gmain( bool Having_Old_instance = true ) {
if (Having_Old_instance) {
Gui->deleteLater();
Gui = 0; /* if not delete other new QMainWindow go open :-) */
}
Gui = new GMain();
Gui->setWindowTitle( _MAINTITLE_APPS_ + " /" + current_language);
const QString usersetfont = Gui->setter.value("DefaultFontsW").toString();
QFont settfont;
settfont.fromString(usersetfont);
if (usersetfont.size() > 0) {
setFont(settfont);
}
Gui->actionLoad_Italiano->setData("it");
Gui->actionLoad_Deutsch->setData("de");
Gui->actionLoad_English->setData("en");
connect(Gui->actionConfigure_DB, SIGNAL(triggered()), Gui, SLOT(OpenSetting()));
connect(Gui->actionLoad_Italiano, SIGNAL(triggered()), this, SLOT(OpenDefault()));
connect(Gui->actionLoad_Deutsch, SIGNAL(triggered()), this, SLOT(OpenDefault()));
connect(Gui->actionLoad_English, SIGNAL(triggered()), this, SLOT(OpenDefault()));
Gui->show();
}
instanzen werden geloscht... mit der sistem sprache... und eine neue geht los mit eine neue sprache einstellung ....
Code: Alles auswählen
void Load_Language( const QString lang )
{
current_language = lang;
#if defined Q_WS_MAC
localedirfile = QString("%1/locale/main_%2.qm").arg(QDir::currentPath()).arg(lang);
#endif
#if defined Q_WS_WIN
localedirfile = QString("%1/locale/main_%2.qm").arg(QCoreApplication::applicationDirPath()).arg(lang);
#endif
#if defined Q_WS_X11
localedirfile = QString("%1/locale/main_%2.qm").arg(QDir::currentPath()).arg(lang);
#endif
QTranslator *translator = new QTranslator(qApp);
translator->load(localedirfile);
qApp->installTranslator(translator);
}
Code: Alles auswählen
void OpenDefault() {
QAction *invoice = qobject_cast<QAction *>(sender());
Load_Language(invoice->data().toString());
Load_New_Gmain();
}
Damit ist es nicht noetig alle sprache uebersetzung in einen Ui:retranslateUi zu packen...
und man kann auch auf die haupt event zugreifen wie zum beispiel iher um die tooltips in einen anderen label zu laden ....
Oder mit den file event file zu oeffnen...
Code: Alles auswählen
bool event(QEvent *ev)
{
bool confirm = false;
if (ev->type() == 112) {
const QString statustxt = static_cast<QStatusTipEvent *>(ev)->tip();
Gui->Msg(statustxt);
confirm = true;
}
if (!confirm) {
return QApplication::event(ev);
} else {
ev->setAccepted(true);
return confirm;
}
}
Die sistem Sprache hohle ich einfach mit:
(dann bin ich sicher das auch window XP MUI als multisparche funkt..)
Code: Alles auswählen
static inline QString UserLanguage()
{
QString languser,languagesistem,langqt;
QLocale loci = QLocale::system();
languser = getenv("LANG");
languser = languser.toLower();
languagesistem = loci.name();
languagesistem = languagesistem.toLower();
languagesistem = languagesistem.left(2);
/* Window XP Prof MUI Multiuser == stay only "c" language && user setting setenv !!! */
if (languagesistem == "c") {
if (languser.size() > 2 && languser.contains("_")) {
languagesistem = languser.left(2);
}
}
return languagesistem;
}