Files
VX5_KRO_GearPump/main.cpp
T
2026-07-01 08:16:05 +08:00

345 lines
10 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#define _GNU_SOURCE // 必须放在所有头文件之前
#include <link.h> // dl_iterate_phdr 的声明
#include <dlfcn.h> // dladdr 等
#include <execinfo.h> // backtrace
#include <QApplication>
#include <QVBoxLayout>
#include <InputMethod.h>
#include <QKeyEvent>
#include <QTextCodec>
#include <QTextEdit>
#include <QFont>
//#include <QWSServer>
#include <stdio.h>
//#include "logo_form.h"
#include "MyInputMethod.h"
//#include "mainwindow.h"
#include <QDebug>
#include <QTranslator>
#include <QMessageBox>
#include <QStyleFactory>
#include <QFontDatabase>
#include "myinclude.h"
#include "Public.h"
#include "mainwidget.h"
#include "InkJetPrinter.h"
#include "Log/filelogger.h"
#include <iostream>
#include <fstream>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <cxxabi.h>
#include <cstdlib>
#include <cstdio>
#include <execinfo.h>
QString gAppNameStr = "";//这是个全局变量,用于后续获取当前运行程序的绝对路径
// 全局变量保存基址
static uintptr_t g_base_address = 0;
// 回调函数:找到当前可执行文件的基址
static int find_base_address(struct dl_phdr_info *info, size_t size, void *data) {
// 检查是否是主程序(第一个加载的通常是主程序)
if (info->dlpi_name == nullptr || info->dlpi_name[0] == '\0') {
// 获取第一个段的加载地址(通常是基址)
g_base_address = info->dlpi_addr;
return 1; // 停止遍历
}
return 0; // 继续遍历
}
// 获取程序基址的函数
uintptr_t get_base_address() {
if (g_base_address == 0) {
dl_iterate_phdr(find_base_address, nullptr);
}
return g_base_address;
}
void createStackTraceFile(const char *fileName, const char *appName)
{
std::ofstream file(fileName);
if (!file.is_open()) {
std::cerr << "Error opening file: " << fileName << std::endl;
return;
}
void *array[100];
size_t size;
char **strings;
size = backtrace(array, 100);
if (size == 0) {
std::cerr << "No stack frames obtained" << std::endl;
return;
}
// 获取程序基址(PIE需要)
uintptr_t base_addr = get_base_address();
strings = backtrace_symbols(array, size);
file << "Stack trace info:\n";
file << "Base address: 0x" << std::hex << base_addr << std::dec << "\n\n";
for (size_t i = 0; i < size; ++i) {
file << strings[i] << std::endl;
// 计算偏移地址:实际地址 - 基址
uintptr_t addr = reinterpret_cast<uintptr_t>(array[i]);
uintptr_t offset = addr - base_addr;
char cmd[512];
// 使用偏移地址而不是实际地址
snprintf(cmd, sizeof(cmd), "addr2line -e %s 0x%lx", appName, offset);
FILE *fp = popen(cmd, "r");
if (fp) {
char line[256];
while (fgets(line, sizeof(line), fp)) {
file << " " << line; // 缩进显示更清晰
}
pclose(fp);
} else {
std::cerr << "Failed to run addr2line command" << std::endl;
}
file << std::endl;
}
free(strings);
file.close();
}
void signalHandler(int signum)
{
// 直接指定固定的路径
QString dumpFileName = "/home/plg/doc/dumpfile.txt";
QString appName = gAppNameStr;
createStackTraceFile(dumpFileName.toUtf8().data(), appName.toUtf8().data());
exit(signum);
}
//#define SYS_CN
/*
1. WenQuanYiMH_12_50.qpf2 是由 Zfull-GB_12_50(Zpix.ttf)在PCMAKEQPF软件下生成的,它包含较完整的字体库 nono 20160302
2. 基于WenQuanYiCN编越南语,中文通用字库
3. 基于WenQuanYiMicroHei编 普通版本字库
#git commit -am "测试提交新数据"
#git push
#git clone xiongnie@119.23.201.56:/var/repo_dir/QtUI.git
#git pull xiongnie@119.23.201.56:/var/repo_dir/QtUI.git
#git remote add origin git@github.com:username/Hello-World.git
#git push origin master 将本地项目给提交到服务器中
#-----------------------------------------------------------
#git pull 本地与服务器端同步
#-----------------------------------------------------------------
#git push (远程仓库名) (分支名) 将本地分支推送到服务器上去。
#git push origin serverfix:awesomebranch
git remote add origin xiongnie@119.23.201.56:/var/repo_dir/QRUIV53.git
###
*/
InkJetPrinter *pInkJectPrinter;
MyInputMethod *myInputMethod;
//#include <X11/Xlib.h>
//#include <X11/X.h>
//#include <X11/Xutil.h>
void loadApplicationFonts();
int main(int argc, char *argv[])
{
//#ifdef MULTILANGUAGE
// qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
//#endif
QString keyBoardType = Public::ReadKeyBoardUse();
// QString keyBoardType = "MultiLanguage";
if(keyBoardType == "MultiLanguage")
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QApplication a(argc, argv);
gAppNameStr = QString::fromUtf8(argv[0]);
signal(SIGSEGV, signalHandler);
signal(SIGABRT, signalHandler);
signal(SIGILL, signalHandler);
signal(SIGFPE, signalHandler);
// 配置日志
QString configFileName = ":/conf/config.ini";
QSettings* logSettings = new QSettings(configFileName, QSettings::IniFormat, &a);
logSettings->beginGroup("logging");
FileLogger* logger = new FileLogger(logSettings, 10000, &a);
logger->installMsgHandler();
qInfo() << "App runtime path: " <<QDir::currentPath();
loadApplicationFonts();
QApplication::setStyle(QStyleFactory::create("Windows"));
QFont f = a.font();
QString langurageFile;
QFile file(SYS_ROOT_DIR"UseEn");
if(file.exists())
{
QString langurageType = Public::ReadLanguageName();//"";//
// QString langurageType= "English";
qDebug()<<"La:"<<langurageType;
if(langurageType=="Turkish") {
f.setFamily("wenquanyi_zh");
langurageFile= "./turkey.qm";
f.setPointSize(12);
f.setPixelSize(12);
}
else if(langurageType=="Spanish")
{
//f.setFamily("WenQuanYiNX");//f.setFamily("Zfull-GB"); //f.setFamily("WenQuanYiMH");//Cambria
f.setFamily("wenquanyi_zh");
langurageFile= "./spanish.qm";
f.setPointSize(12);
f.setPixelSize(12);
}
else if(langurageType=="Thai")
{
//f.setFamily("WenQuanYiNX");//f.setFamily("Zfull-GB"); //f.setFamily("WenQuanYiMH");//Cambria
f.setFamily("Kanit");
langurageFile= "./thai.qm";
f.setPointSize(12);
f.setPixelSize(12);
}
else if(langurageType=="Vietnamese") {
f.setFamily("Arial");//f.setFamily("Zfull-GB"); //f.setFamily("WenQuanYiMH");//Cambria
f.setPointSize(12);
//f.setFixedPitch(1);
f.setPixelSize(12);
langurageFile= "./vena.qm";
}
else if(langurageType=="English") {
f.setFamily("Arial");
#ifdef EnableBangla
f.setFamily("wenquanyi_zh");
#endif
langurageFile= "./english.qm";
f.setPointSize(12);
f.setPixelSize(12);
}
else if(langurageType=="Farsi") {
//f.setFamily("WenQuanYiNX");//f.setFamily("Zfull-GB"); //f.setFamily("WenQuanYiMH");//Cambria
f.setFamily("Arial");
langurageFile= "./farsi.qm";
f.setPointSize(12);
f.setPixelSize(12);
}
else if(langurageType=="Korean") {
// f.setFamily("Microsoft YaHei Light");
f.setFamily("NanumSquareRound");
langurageFile= "./korean.qm";
f.setPointSize(14);
f.setPixelSize(14);
// f.setLetterSpacing(1,8);
}
else{
f.setFamily("WenQuanYi Micro Hei");
f.setPointSize(18);
f.setPixelSize(18);
langurageFile ="./qt_zh_CN.qm";
}
}
else{
langurageFile ="./qt_zh_CN.qm";
f.setFamily("WenQuanYi Micro Hei");
f.setPointSize(16);
f.setPixelSize(16);
}
a.setFont(f);
/*-------------------------------------------------*/
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
/*------------------语言国际化-------------------------*/
QTranslator *translator = new QTranslator();
if(translator->load(langurageFile)==false){
translator->deleteLater();
QMessageBox::critical(0,("错误"),("无法加载中文翻译文件") + langurageFile);
}
else {
QApplication::installTranslator(translator);
}
myInputMethod = new MyInputMethod();//edit@02-07
InkJetPrinter w;
#ifndef Q_OS_WIN32
w.setWindowTitle(("比洋喷码"));
#endif
if (QSysInfo::buildCpuArchitecture().contains("x86")) {
qDebug() << "Running in Debug mode";
w.show();
} else {
qDebug() << "Running in Release mode";
w.showFullScreen();
}
pInkJectPrinter = &w;
return a.exec();
}
void loadApplicationFonts() {
QStringList fontPaths = {
"/usr/lib/fonts/YaHeiBold-5pt-6.bdf",
"/usr/lib/fonts/YaHeiBold-7pt-8.bdf",
"/usr/lib/fonts/YaHeiBold-9pt-10.bdf",
"/usr/lib/fonts/YaHeiBold-12pt-13.bdf",
"/usr/lib/fonts/YaHeiBold-16pt-17.bdf",
"/usr/lib/fonts/WenQuanYiMedium-5pt-6.bdf",
"/usr/lib/fonts/WenQuanYiMedium-7pt-8.bdf",
"/usr/lib/fonts/DinkieBitmap9pxMedium-9pt-10.bdf",
"/usr/lib/fonts/WenQuanYiMedium-12pt-13.bdf",
"/usr/lib/fonts/WenQuanYiMedium-16pt-17.bdf",
"/usr/lib/fonts/WenQuanYiMedium-24pt-25.bdf",
"/usr/lib/fonts/WenQuanYiMedium-32pt-33.bdf",
"/usr/lib/fonts/WenQuanYiMicroHei.ttf",
"/usr/lib/fonts/msyhl_12pt.bdf",
"/usr/lib/fonts/arial.ttf",
"/usr/lib/fonts/YanglabeldotMedium-12pt-13.bdf",
"/usr/share/fonts/truetype/nanum/NanumSquareRoundR.ttf"
};
foreach (const QString &path, fontPaths) {
if (QFile::exists(path)) {
int fontId = QFontDatabase::addApplicationFont(path);
if (fontId == -1) {
qDebug()<< "Failed to load font:" << path;
} else {
qDebug()<< "Loaded font:" << path<< "ID:"<< fontId;
}
}
}
}