#include #include "cdatabaseinterface.h" #include #include #include //#include "loginwidget.h" #include "cmainwindow.h" #include "readconfig.h" #include "loginwidget.h" #include "gamecontrol.h" #include #include #include #include #include "fescontroldialog.h" #include void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) { static QMutex mutex; mutex.lock(); QString text; switch(type) { case QtDebugMsg: text = QString("Debug:"); break; case QtWarningMsg: text = QString("Warning:"); break; case QtCriticalMsg: text = QString("Critical:"); break; case QtFatalMsg: text = QString("Fatal:"); } QString context_info = QString("File:(%1) Line:(%2)").arg(QString(context.file)).arg(context.line); QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss ddd"); QString current_date = QString("(%1)").arg(current_date_time); QString message = QString("%1 %2 %3 %4").arg(text).arg(context_info).arg(msg).arg(current_date); QFile file("log.txt"); file.open(QIODevice::WriteOnly | QIODevice::Append); QTextStream text_stream(&file); text_stream << message << "\r\n"; file.flush(); file.close(); mutex.unlock(); } #include #include //设置程序自启动 appPath程序路径 void SetProcessAutoRunSelf(const QString &appPath) { //注册表路径需要使用双反斜杠,如果是32位系统,要使用QSettings::Registry32Format QSettings settings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::Registry64Format); //以程序名称作为注册表中的键 //根据键获取对应的值(程序路径) QFileInfo fInfo(appPath); QString name = fInfo.baseName(); QString path = settings.value(name).toString(); //如果注册表中的路径和当前程序路径不一样, //则表示没有设置自启动或自启动程序已经更换了路径 //toNativeSeparators的意思是将"/"替换为"\" QString newPath = QDir::toNativeSeparators(appPath); if (path != newPath) { settings.setValue(name, newPath); qDebug() <<"添加快捷启动注册表:HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run,"; } } int main(int argc, char *argv[]) { qputenv("QT_IM_MODULE", QByteArray("tgtsml")); //qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); QApplication a(argc, argv); //Qt开机自启动 //SetProcessAutoRunSelf(qApp->applicationFilePath()); #ifdef DEBUGON qInstallMessageHandler(outputMessage); #endif //数据库读取 if(!CDatabaseInterface::getInstance()->openDB("./DependFile/DBFile/UpLow.db","QSQLITE")) qDebug()<<"UpLow.db open failed!"; //配置文件读取 if(!ReadConfig::getInstance()->readConfigFile()) { qDebug()<<"配置文件读取失败"; return -1; } //读取游戏配置文件 GameControl::getInstance()->readGameConfigMsg(); //设置全局样式表 QFile file("./DependFile/QSS/app.txt"); if(file.open(QFile::ReadOnly)) { QString styleSheet = QLatin1String(file.readAll()); qApp->setStyleSheet(styleSheet); file.close(); } else { QMessageBox::warning(NULL, "warning", "totalqss Open failed", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); } QSharedMemory sharedMemory; sharedMemory.setKey("main_Window"); if(sharedMemory.attach()) { QMessageBox::warning(NULL, "Warning", ("不可重复开启进程")); return 0; } LoginWidget login;// CMainWindow w; if(sharedMemory.create(1)) { QObject::connect(&w,SIGNAL(signalShowCompleted()),&login,SLOT(slotShowCompleted())); login.setWindowModality(Qt::WindowModal);// login.exec(); // w.show(); } QObject::connect(&a,&QApplication::aboutToQuit,[](){ FesControlDialog::getInstance()->turnoffDevice(1,1); }); return a.exec(); }