2#include <QStandardPaths>
9#include <QGuiApplication>
10#include <QQmlApplicationEngine>
25#if Q_OS_MSDOS || defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
26#define VERSION "1.0.0"
38 return QString(
"%1%2%3").arg(thisAppDataLocation, QDir::separator(),
"messageLog.txt");
46 return QString(
"%1: %2").arg(QObject::tr(
"Failed to open log file"), thisAppDataLocation);
55 if (QFileInfo::exists(theFullFilePath) && QFileInfo(theFullFilePath).isFile())
56 { QFile::remove(theFullFilePath); }
57 QFile theFile(theFullFilePath);
58 if(!theFile.open(QFile::WriteOnly | QFile::Text | QIODevice::Truncate))
60 QString theErrorMessage = QString(
"%1: %2").arg(QObject::tr(
"Could not open log file"), theFullFilePath);
61 std::cout << theErrorMessage.toStdString() << std::endl;
65 QTextStream theFileStream(&theFile);
66 const QDateTime theDateTimeStamp = QDateTime::currentDateTime();
67 QString theDateStamp = QString(
"%1: %2 - %3 %4").arg(QObject::tr(
"Log File"), thisAppName, theDateTimeStamp.toString(
"dd MMM yyyy hh:mm:ss"), theDateTimeStamp.timeZoneAbbreviation());
68 theFileStream << theDateStamp <<
'\n';
71 if (QFileInfo::exists(theFullFilePath) && QFileInfo(theFullFilePath).isFile())
86 if(!theFileHandle.open( QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text ))
89 std::cout << QObject::tr(
"Log File failed to open").toStdString() <<
": " <<
myLogFile.toStdString() << std::endl;
92 QTextStream theFileStream(&theFileHandle);
93 theFileStream << thisMessage;
94 theFileStream.flush();
95 theFileHandle.close();
101void myMessageHandler(QtMsgType thisType,
const QMessageLogContext &thisContext,
const QString &thisMsg)
103 QByteArray theLocalMsg = thisMsg.toLocal8Bit();
104 const char *theFile = thisContext.file ? thisContext.file :
"";
105 const char *theFunction = thisContext.function ? thisContext.function :
"";
110 logEvents(QString(
"Debug: %1 (%2:%3, %4)\n").arg(theLocalMsg.constData(), theFile, QString::number(thisContext.line), theFunction));
111 fprintf(stderr,
"Debug: %s (%s:%u, %s)\n", theLocalMsg.constData(), theFile, thisContext.line, theFunction);
114 logEvents(QString(
"Info: %1 (%2:%3, %4)\n").arg(theLocalMsg.constData(), theFile, QString::number(thisContext.line), theFunction));
115 fprintf(stderr,
"Info: %s (%s:%u, %s)\n", theLocalMsg.constData(), theFile, thisContext.line, theFunction);
118 logEvents(QString(
"Warning: %1 (%2:%3, %4)\n").arg(theLocalMsg.constData(), theFile, QString::number(thisContext.line), theFunction));
119 fprintf(stderr,
"Warning: %s (%s:%u, %s)\n", theLocalMsg.constData(), theFile, thisContext.line, theFunction);
122 logEvents(QString(
"Critical: %1 (%2:%3, %4)\n").arg(theLocalMsg.constData(), theFile, QString::number(thisContext.line), theFunction));
123 fprintf(stderr,
"Critical: %s (%s:%u, %s)\n", theLocalMsg.constData(), theFile, thisContext.line, theFunction);
126 logEvents(QString(
"Fatal: %1 (%2:%3, %4)\n").arg(theLocalMsg.constData(), theFile, QString::number(thisContext.line), theFunction));
127 fprintf(stderr,
"Fatal: %s (%s:%u, %s)\n", theLocalMsg.constData(), theFile, thisContext.line, theFunction);
140 Utils(QObject* parent =
nullptr) : QObject(parent) { }
141 Q_INVOKABLE
static QUrl
fromUserInput(
const QString& userInput);
149 if (userInput.isEmpty())
return QUrl::fromUserInput(
"about:blank");
150 const QUrl result = QUrl::fromUserInput(userInput);
151 return result.isValid() ? result : QUrl::fromUserInput(
"about:blank");
162int main(
int argc,
char *argv[])
164 QString theAppName =
"QtLingo";
165 QString theAppDisplayName =
"Qt Lingo";
166 bool isDebugMessage =
true;
168 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
171 QGuiApplication theApplication(argc, argv);
172 QGuiApplication::setWindowIcon(QIcon(
":/images/logo32.png"));
173 QQmlApplicationEngine theEngine;
174 QQmlContext *theContext = theEngine.rootContext();
176 QGuiApplication::setApplicationDisplayName(QCoreApplication::translate(
"main", theAppDisplayName.toLocal8Bit()));
179 Q_INIT_RESOURCE(QtLingo);
180 QApplication theApplication(argc, argv);
181 QApplication::setWindowIcon(QIcon(
":/images/logo32.png"));
185 theApplication.setOrganizationName(theAppName);
186 theApplication.setApplicationName(theAppName);
187 theApplication.setApplicationDisplayName(theAppDisplayName);
188 theApplication.setApplicationVersion(
VERSION);
211 theContext->setContextProperty(
"thisLanguageList", theLanguageModel->
getLanguageList());
215 theContext->setContextProperty(
"thisDefaultLanguageName", theLanguageName);
217 theContext->setContextProperty(
"thisLanguageModel", theLanguageModel);
219 theContext->setContextProperty(
"isDebugMessage", isDebugMessage);
221 const QUrl theQmlUrl(QStringLiteral(
"qrc:/qml/main.qml"));
222 QObject::connect(&theEngine, &QQmlApplicationEngine::objectCreated, &theApplication, [theQmlUrl](QObject *obj,
const QUrl &objUrl)
224 if (!obj && theQmlUrl == objUrl)
225 { QCoreApplication::exit(-1); }
226 }, Qt::QueuedConnection);
227 theEngine.load(theQmlUrl);
228 if (theEngine.rootObjects().isEmpty())
return -1;
238 theMainWindow->show();
240 return theApplication.exec();
Main Window Constructor. /class MainWindow.
void setLanguageModel(MyLanguageModel *thisLanguageModel)
set Language Model
Abstact Model used for ComboBox. /class MyLanguageModel.
void setTransFilePrefix(const QString &thisTransFilePrefix)
set TransFile Prefix
Q_INVOKABLE void setLanguages()
set Languages
QString getDefaultLanguageCode()
get Default Language Code
void setTranslationSource(const QString &thisTranslationSource)
set Translation Source
Q_INVOKABLE QStringList & getLanguageList()
get Language List
void setHelpSource(const QString &thisHelpSource)
set Help Source
MyOrgSettings * mySetting
mySetting
const QString MY_LOCALE_LANG_NAME
MY_LOCALE_LANG_NAME
QString getAppDataLocation()
get AppData Location
void setIniFileName(const QString &thisIniFileName)
set IniFile
void setVersion(const QString &thisVersion)
set Version
QString readSettings(const QString &thisSetting, const QString &thisDefault)
read Settings
Utils. Utils Workaround: As of Qt 5.4 QtQuick does not expose QUrl::fromUserInput.
static Q_INVOKABLE QUrl fromUserInput(const QString &userInput)
fromUserInput. fromUserInput
Utils(QObject *parent=nullptr)
int main(int argc, char *argv[])
main.moc. main.moc must be included below to define above
bool setMessageLogFile(const QString &thisAppName, const QString &thisAppDataLocation)
QString getMessageLogFile(const QString &thisAppDataLocation)
void myMessageHandler(QtMsgType thisType, const QMessageLogContext &thisContext, const QString &thisMsg)
QString getFileErrorMessage(const QString &thisAppDataLocation)
void logEvents(const QString &thisMessage)