QFileInfo fi(qApp->applicationFilePath()); QString filename( fi.absolutePath() +"/"+ fi.baseName()+".log" );
static inline QString getDefaultResourcePath(){#if defined Q_OS_WIN return qApp->applicationDirPath();#elif defined Q_OS_MACX return ("/Resources");#elif defined Q_OS_UNIX // not Mac UNIXes return (QStiring('/usr/local/share/') + qApp->applicationName());#endif}
bool isDebug = false;/// Разбор параметров запускаvoid parseArg(int argc, char *argv[]){ for (int i=1; i<argc; i++) if (strcmp(argv[i], "-debug")==0) isDebug = true; /// Включение расширенной отладки}/// Перенаправление отладочного выводаvoid myMessageOutput(QtMsgType type, const char *msg){ QString filename("debug.log"); if (qApp) filename = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + qApp->applicationName() + qApp->applicationVersion() + "." + QString::number(qApp->applicationPid()) + ".log"; FILE *file; file = fopen(filename.toStdString().c_str(), "a"); if (file) { switch (type) { case QtDebugMsg: fprintf(file, "Debug: %s\n", msg); break; case QtWarningMsg: fprintf(file, "Warning: %s\n", msg); break; case QtCriticalMsg: fprintf(file, "Critical: %s\n", msg); break; case QtFatalMsg: fprintf(file, "Fatal: %s\n", msg); abort(); } fclose(file); } #ifndef QT_NO_DEBUG isDebug = true; #endif if (isDebug || !file) { QString wstr(QString(msg)+"\n"); OutputDebugString((WCHAR*)wstr.constData()); if(type == QtFatalMsg) { asm("int $0x3"); abort(); } }}
QString settingsFile("settings.ini"); if (qApp) filename = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + qApp->applicationName() + ".ini";