活动介绍

#include <windows.h> #include <QString> #include <QMessageBox> int main(int argc, char *argv[]) { HANDLE mutex = ::CreateMutex(Q_NULLPTR, true, (LPCWSTR)qApp->applicationName().toStdWString().c_str()); if (GetLastError() == ERROR_ALREADY_EXISTS) { QMessageBox waringBox(QMessageBox::Warning, QStringLiteral("警告"), QStringLiteral("当前程序已运行,不能再次运行!")); waringBox.setButtonText(QMessageBox::Ok, QStringLiteral("确定")); waringBox.setStandardButtons(QMessageBox::Ok); waringBox.exec(); ::CloseHandle(mutex); return 0; } // 获取当前登录用户的会话ID DWORD sessionId; ProcessIdToSessionId(GetCurrentProcessId(), &sessionId); // 遍历所有用户会话,关闭其他用户会话中的该程序进程 DWORD sessionCount; if (ProcessIdToSessionId(GetCurrentProcessId(), &sessionId) && WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTS_INFO_CLASS::WTS_SESSION, (LPWSTR*)&sessionCount, &sessionId)) { WTS_SESSION_INFO* pSessionInfo = NULL; if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &sessionCount)) { for (DWORD i = 0; i < sessionCount; i++) { DWORD processCount; if (WTSEnumerateProcesses(pSessionInfo[i].hServer, pSessionInfo[i].SessionId, 1, (PWTS_PROCESS_INFO*)&processCount)) { WTS_PROCESS_INFO* pProcessInfo = NULL; if (WTSEnumerateProcesses(pSessionInfo[i].hServer, pSessionInfo[i].SessionId, 1, &pProcessInfo, &processCount)) { for (DWORD j = 0; j < processCount; j++) { if (pProcessInfo[j].SessionId != sessionId && wcsstr(pProcessInfo[j].pProcessName, qApp->applicationName().toStdWString().c_str())) { HANDLE hProcess = ::OpenProcess(PROCESS_TERMINATE, FALSE, pProcessInfo[j].ProcessId); if (hProcess) { ::TerminateProcess(hProcess, 0); ::CloseHandle(hProcess); } } } ::WTSFreeMemory(pProcessInfo); } } } ::WTSFreeMemory(pSessionInfo); } } // 正常执行程序 QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } 上面代码会报出 error: 'WTS_CURRENT_SERVER_HANDLE' was not declared in this scope错误,请修复后给我完整代码

时间: 2024-01-13 16:02:48 浏览: 202
好的,根据您提供的代码,我发现需要添加一个头文件 `wtsapi32.h` 来解决该错误。修改后的完整代码如下: ``` #include <windows.h> #include <wtsapi32.h> #include <QString> #include <QMessageBox> int main(int argc, char *argv[]) { HANDLE mutex = ::CreateMutex(Q_NULLPTR, true, (LPCWSTR)qApp->applicationName().toStdWString().c_str()); if (GetLastError() == ERROR_ALREADY_EXISTS) { QMessageBox waringBox(QMessageBox::Warning, QStringLiteral("警告"), QStringLiteral("当前程序已运行,不能再次运行!")); waringBox.setButtonText(QMessageBox::Ok, QStringLiteral("确定")); waringBox.setStandardButtons(QMessageBox::Ok); waringBox.exec(); ::CloseHandle(mutex); return 0; } // 获取当前登录用户的会话ID DWORD sessionId; ProcessIdToSessionId(GetCurrentProcessId(), &sessionId); // 遍历所有用户会话,关闭其他用户会话中的该程序进程 DWORD sessionCount; if (ProcessIdToSessionId(GetCurrentProcessId(), &sessionId) && WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTS_INFO_CLASS::WTS_SESSION, (LPWSTR*)&sessionCount, &sessionId)) { WTS_SESSION_INFO* pSessionInfo = NULL; if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &sessionCount)) { for (DWORD i = 0; i < sessionCount; i++) { DWORD processCount; if (WTSEnumerateProcesses(pSessionInfo[i].hServer, pSessionInfo[i].SessionId, 1, (PWTS_PROCESS_INFO*)&processCount)) { WTS_PROCESS_INFO* pProcessInfo = NULL; if (WTSEnumerateProcesses(pSessionInfo[i].hServer, pSessionInfo[i].SessionId, 1, &pProcessInfo, &processCount)) { for (DWORD j = 0; j < processCount; j++) { if (pProcessInfo[j].SessionId != sessionId && wcsstr(pProcessInfo[j].pProcessName, qApp->applicationName().toStdWString().c_str())) { HANDLE hProcess = ::OpenProcess(PROCESS_TERMINATE, FALSE, pProcessInfo[j].ProcessId); if (hProcess) { ::TerminateProcess(hProcess, 0); ::CloseHandle(hProcess); } } } ::WTSFreeMemory(pProcessInfo); } } } ::WTSFreeMemory(pSessionInfo); } } // 正常执行程序 QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } ``` 需要注意的是,添加了 `wtsapi32.h` 的头文件之后,编译时需要链接该库文件 `wtsapi32.lib`,否则会出现 `LNK2019` 错误。
阅读全文

相关推荐

qt程序如下: mainwindow.cpp 的内容: #include "mainwindow.h" #include <QSqlDatabase> #include <QDebug> #include <QSqlQuery> #include <QMessageBox> #include #include <stdio.h> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { qDebug() << "available drivers:"; QStringList drivers = QSqlDatabase::drivers(); foreach (QString driver, drivers) qDebug() << driver; QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("127.0.0.1"); // 需要改成自己的对应的端口号 db.setDatabaseName("highgo"); // 数据库名称,需要改成自己的 db.setPort(5866); // 端口号,需要改成自己的 db.setUserName("sysdba"); // 用户名,需要改成自己的 db.setPassword("Hello@1234567"); // 用户密码,需要改成自己的 if (db.open()) { QMessageBox::information(this, "Info", "Database connection successful"); // 执行查询语句 QSqlQuery query; if (query.exec("SELECT version();")) { if (query.next()) { // 获取查询结果 QString version = query.value(0).toString(); QMessageBox::information(this, "Database Version", version, QMessageBox::Yes | QMessageBox::No ); } else { QMessageBox::warning(this, "Query Error", "No data returned from query"); } puts("44444"); } else { QMessageBox::warning(this, "Query Error", "Failed to execute query"); } puts("55555"); } else { QMessageBox::critical(this, "Error", "Failed to open database"); } db.close(); puts("33333"); //setAttribute(Qt::WA_DeleteOnClose); } MainWindow::~MainWindow() { puts("77777"); } main.cpp 的内容: #include "mainwindow.h" #include <QApplication> #include <stdio.h> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); w.close(); printf("22222"); return a.exec(); } mainwindow.h 的内容: #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = NULL); ~MainWindow(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H 程序执行后 ,数据库能登录上,也有查询结果,但程序卡住没有关闭,终端输出 44444 55555 33333

#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H ----------------------------------------------- #include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } 以上两个是.h和.cpp代码 --------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <rect> <x>0</x> <y>0</y> <width>932</width> <height>628</height> </rect> <string>MainWindow</string> <widget class="QWidget" name="centralwidget"> <widget class="QPushButton" name="pb_connect"> <rect> <x>40</x> <y>20</y> <width>89</width> <height>25</height> </rect> <string>连接</string> </widget> <widget class="QPushButton" name="pb_led0"> <rect> <x>40</x> <y>70</y> <width>89</width> <height>25</height> </rect> <string>led0_on</string> </widget> <widget class="QPushButton" name="pb_led1"> <rect> <x>40</x> <y>110</y> <width>89</width> <height>25</height> </rect> <string>led1_on</string> </widget> <widget class="QPushButton" name="pb_led2"> <rect> <x>40</x> <y>150</y> <width>89</width> <height>25</height> </rect> <string>led2_on</string> </widget> <widget class="QPushButton" name="pb_feng"> <rect> <x>40</x> <y>190</y> <width>89</width> <height>25</height> </rect> <string>feng_on</string> </widget> <widget class="QPushButton" name="pb_buzzer"> <rect> <x>140</x> <y>20</y> <width>89</width> <height>25</height> </rect> <string>蜂鸣器_on</string> </widget> <widget class="QPushButton" name="pb_humiture"> <rect> <x>140</x> <y>70</y> <width>89</width> <height>25</height> </rect> <string>温湿度_on</string> </widget> <widget class="QPushButton" name="pb_photosensitive"> <rect> <x>140</x> <y>110</y> <width>89</width> <height>25</height> </rect> <string>光敏_on</string> </widget> <widget class="QPushButton" name="pb_infrared"> <rect> <x>140</x> <y>150</y> <width>89</width> <height>25</height> </rect> <string>人体红外_on</string> </widget> <widget class="QPushButton" name="pb_camera"> <rect> <x>140</x> <y>190</y> <width>89</width> <height>25</height> </rect> <string>摄像头_on</string> </widget> <widget class="QTextBrowser" name="textBrowser"> <rect> <x>350</x> <y>10</y> <width>421</width> <height>211</height> </rect> </widget> </widget> <widget class="QMenuBar" name="menubar"> <rect> <x>0</x> <y>0</y> <width>932</width> <height>28</height> </rect> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/> </ui> 以上是.ui代码 --------------------------------------------------------- 目前项目进度: 当前项目结构如下: DXM1txst: DXM1txst.pro Headers: fsmpBeeper.h fsmpElectric.h fsmpEvents.h fsmpFan.h fsmpLed.h fsmpLight.h fsmpProximity.h fsmpsevensegLed.h fsmpTempHum.h fsmpvibrator.h mainwindow.h Sources: main.cpp mainwindow.cpp Forms: mainwindow.ui qtcreator内:ui界面中已经有组件:pb_connect(连接按钮)、pb_led0(电灯1开关按钮)、pb_led1(电灯2开关按钮)、pb_led2(电灯3开关按钮)、pb_feng(风扇开关按钮)、pb_buzzer(蜂鸣器开关按钮)、pb_humiture(温湿度传感器开关按钮)、pb_photosensitive(光敏传感器开关按钮)、pb_infrared(人体红外传感器开关按钮)、pb_camera(摄像头开关按钮)、textBrowser(用于接收和发布的消息显示)。 华清远见元宇宙实验中心物联网仿真系统内:所需的所以硬件的3D场景设计完毕,M4网关单元的Mqtt配置为: 地址:mqtt.yyzlab.com.cn 端口:1883 与应用层、云端交互的Topic: 订阅:1752365375766/APP2AIOTSIM 发布:1752365375766/AIOTSIM2APP 与硬件交互的Topic: 订阅:1752365382482/Device2AIOTSIM 发布:1752365382482/AIOTSIM2Device 与华清远见元宇宙实验中心物联网仿真系统内硬件开关发布的控制码为:电灯0开:{"lamp":true,"id":0},电灯0关:{"lamp":false,"id":0},电灯1开:{"lamp":true,"id":1},电灯1关:{"lamp":false,"id":1},电灯2开:{"lamp":true,"id":2},电灯2关:{"lamp":false,"id":2},风扇开:{"fan":true,"id":0},风扇关:{"fan":false,"id":0},人体红外传感器开:{"infrared ":true,"id":0},人体红外传感器关:{"infrarrared ":false,"id":0},温湿度传感器:{"tem":38.8,"hum":65.7,"id":0},光敏传感器:{"light":43037.0,"id":0} Stm32mp157开发板:所有需要的硬件部署完毕,硬件的.h代码如下(硬件的.h代码已经放入qtcreator项目下的Headers文件夹下,且硬件的所有.h文件内代码都不能再进行修改): fsmpBeeper.h: #ifndef FSMPBEEPER_H #define FSMPBEEPER_H /*************************************************************************** * * 类名:fsmpBeeper * 功能说明:扩展板 蜂鸣器 * 公有函数: * fsmpBeeper() * bool setRate(uint32_t rate) 设置频率 * bool start(void) 启动蜂鸣器 * bool stop(void) 关闭蜂鸣器 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> /* FSMP开发板(linux)蜂鸣器操作类 v0 2023/1/9 by 张城 */ class fsmpBeeper:public QObject{ Q_OBJECT public: explicit fsmpBeeper(const char *device = "/dev/input/event0", QObject *parent = nullptr) :QObject(parent) { event.type = EV_SND; time.tv_sec = 1; time.tv_usec = 0; event.time = time; beeper_fd = ::open(device,O_RDWR); if(beeper_fd < 0) { perror("open_beeper"); return; } }; ~fsmpBeeper() { ::close(beeper_fd); } /* * Description: 设置频率值 * input: rate 频率 * output: null * return: 成功true/失败false */ bool setRate(uint32_t rate = 1000) { if(rate > 0) { event.code = SND_TONE; event.value = rate; return true; } return false; } /* * Description: start设备 * input: null * output: null * return: 成功true/失败false */ bool start(void) { int ret = write(beeper_fd, &event, sizeof(struct input_event)); if(ret < 0) { perror("write"); return false; } return true; } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ bool stop(void) { struct input_event event; event.type = EV_SND; event.code = SND_BELL; event.value = 0000; time.tv_sec = 1; time.tv_usec = 0; event.time = time; int ret = write(beeper_fd, &event, sizeof(struct input_event)); if(ret < 0) { perror("write"); return false; } return true; } private: int beeper_fd; //设备文件描述符 struct input_event event; struct timeval time; }; #endif // FSMPBEEPER_H ------------------------------------------------------- fsmpElectric.h: #ifndef ELC_H #define ELC_H /*************************************************************************** * * 类名:fsmpElectric * 功能说明:扩展板 电气信息检测 * 公有函数: * fsmpElectric() * float voltagemV(void) 获取电压mv(旋钮控制) * float currentmA(void) 获取电流ma(板载设备真实电流) * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <stdint.h> #include <QDebug> class fsmpElectric:public QObject{ Q_OBJECT public: explicit fsmpElectric(QObject *parent = nullptr) :QObject(parent) { } ~fsmpElectric(){ } float voltagemV(void) { electric_fd1 = open("/sys/bus/iio/devices/iio:device3/in_voltage1_raw",O_RDONLY|O_NONBLOCK); if(electric_fd1 < 0) { perror("open"); return -1; } char buf[10] = {0}; int ret = read(electric_fd1,buf,sizeof(buf)); if(ret < 0) { perror("read"); return -1; } int val = 0; sscanf(buf,"%d",&val); ::close(electric_fd1); return (float)3300 * val / 65536; } float currentmA(void) { electric_fd0 = open("/sys/bus/iio/devices/iio:device3/in_voltage0_raw",O_RDONLY|O_NONBLOCK); if(electric_fd0 < 0) { perror("open"); return -1; } char buf[10] = {0}; int ret = read(electric_fd0,buf,sizeof(buf)); if(ret < 0) { perror("read"); return -1; } int val = 0; sscanf(buf,"%d",&val); ::close(electric_fd0); return ((((float)3300 * val) /65536)/(10 + 100*1000 + 1000)) * 1000 / 0.1; } private: int electric_fd0; //设备文件描述符 int electric_fd1; //设备文件描述符 }; #endif // ELC_H ------------------------------------------------------- fsmpEvents.h: #ifndef ENV_H #define ENV_H /*************************************************************************** * * 类名:fsmpEvents * 功能说明:扩展板 按钮、人体红外、光闸管、火焰 * 公有函数: * fsmpEvents() * 信号: * void lightTriggered(); 光闸管阻隔 * void flameDetected(); 火焰检测 * void peopleDetected(bool); 人体红外发现true/离开false * void keyPressed(int keynum); 按键按下 keynum: 1、2、3 * void keyRelessed(int keynum); 按键释放 keynum: 1、2、3 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <QTimer> #include #include <sys/ioctl.h> #include <QDebug> #include <QProcess> #include <QThread> #include <stdio.h> #include <stdlib.h> class fsmpEvents:public QObject{ Q_OBJECT signals: /* edge trigle !!!*/ void lightTriggered();//光电开关 void flameDetected();//火焰检测 void peopleDetected(bool);//人体红外 void keyPressed(int keynum); void keyRelessed(int keynum); public: explicit fsmpEvents(QObject *parent = nullptr):QObject(parent) { this->gpio_F_open(); this->gpio_E_open(); fs_timer = new QTimer(this); connect(fs_timer,SIGNAL(timeout()),this,SLOT(time_out())); fs_timer->start(10); }; private: bool gpio_F_open(const char *device = "/dev/gpiochip5") { int ret; int fd = open(device,O_RDONLY|O_NONBLOCK); if(fd < 0) { fprintf(stderr,"open"); return false; } event_req.lineoffset = 9; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_FALLING_EDGE|GPIOEVENT_REQUEST_RISING_EDGE; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } key_1_fd = event_req.fd; int flags = fcntl(key_1_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(key_1_fd,F_SETFL,flags); event_req.lineoffset = 8; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } key_3_fd = event_req.fd; flags = fcntl(key_3_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(key_3_fd,F_SETFL,flags); #if 0 event_req.lineoffset = 5; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } fire_fd = event_req.fd; flags = fcntl(fire_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(fire_fd,F_SETFL,flags); #endif // fire req.lineoffsets[0] = 5; req.flags = GPIOHANDLE_REQUEST_INPUT; // strcpy(req.consumer_label, "fire"); req.lines = 1; memcpy(req.default_values, &data, sizeof(req.default_values)); ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); if (ret == -1) { fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); } fire_fd = req.fd; // key2 req.lineoffsets[0] = 7; req.flags = GPIOHANDLE_REQUEST_INPUT; // strcpy(req.consumer_label, "key2"); req.lines = 1; memcpy(req.default_values, &data, sizeof(req.default_values)); ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); if (ret == -1) { fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); } key_2_fd = req.fd; // people req.lineoffsets[0] = 12; req.flags = GPIOHANDLE_REQUEST_INPUT; // strcpy(req.consumer_label, "key2"); req.lines = 1; memcpy(req.default_values, &data, sizeof(req.default_values)); ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req); if (ret == -1) { fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIO_GET_LINEHANDLE_IOCTL", ret, strerror(errno)); } people_fd = req.fd; return true; } bool gpio_E_open(const char *device = "/dev/gpiochip4") { int ret; int fd = open(device,O_RDONLY|O_NONBLOCK); if(fd < 0) { fprintf(stderr,"open"); return false; } event_req.lineoffset = 15; //TODO event_req.handleflags = GPIOHANDLE_REQUEST_INPUT; event_req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &event_req); // event测试的时候用这个 if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue GET LINEHANDLE IOCTL (%d)\n", ret); } light_trigger_fd = event_req.fd; int flags = fcntl(light_trigger_fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(light_trigger_fd,F_SETFL,flags); return true; } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ bool close(void); public slots: void time_out() { static int key_1_flag = 0; static int key_2_flag = 0; static int key_3_flag = 0; static int light_trigger_flag = 0; static int people_flag = 0; static int flame_flag = 0; //捕获key_1按下 read(key_1_fd,&event_data,sizeof (event_data)); if(event_data.id == 2) { key_1_flag = 1; emit(this->keyPressed(1)); //qDebug()<<"key_1 pressed"; event_data.id = 0; } else if(event_data.id == 1 && key_1_flag==1) { key_1_flag = 0; emit keyRelessed(1); //qDebug()<<"key_1 relessed"; } event_data.id = 0; //捕获key_2按下 int ret = ioctl(key_2_fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret, strerror(errno)); exit(ret); } //qDebug() << "==========" << data.values[0]; if(data.values[0] ==0&&key_2_flag==0) { emit(this->keyPressed(2)); key_2_flag = 1; //qDebug()<<"key_2 pressed"; } else if(data.values[0] ==1&&key_2_flag==1) { key_2_flag = 0; emit keyRelessed(2); //qDebug()<<"key_2 relessed"; } //event_data.id = 0; //捕获key_3按下 read(key_3_fd,&event_data,sizeof (event_data)); //qDebug() << "key3 "<< event_data.id; if(event_data.id == 2 && key_3_flag==0) { key_3_flag = 1; emit(this->keyPressed(3)); //qDebug()<<"key_3 pressed"; event_data.id = 0; } else if(event_data.id == 1 && key_3_flag==1) { key_3_flag = 0; emit keyRelessed(3); //qDebug()<<"key_3 relessed"; } event_data.id = 0; //捕获光电开关 read(light_trigger_fd,&event_data,sizeof (event_data)); if(event_data.id == 1 && light_trigger_flag==0) { //qDebug()<<"light triggered"; light_trigger_flag = 1; emit(this->lightTriggered()); } else light_trigger_flag = 0; event_data.id = 0; //捕获people coming ret = ioctl(people_fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret, strerror(errno)); exit(ret); } if(data.values[0] ==1&&people_flag==0) { emit(this->peopleDetected(true)); people_flag = 1; //qDebug()<<"people coming"; } else if(data.values[0] ==0&&people_flag==1) { people_flag = 0; emit(this->peopleDetected(false)); //qDebug()<<"people leave"; } #if 0 //捕获火焰检测 read(fire_fd,&event_data,sizeof (event_data)); qDebug() << "------------------"<<event_data.id; if(event_data.id == 2 && flame_flag == 0) { qDebug()<<"flamedetection on"; flame_flag = 1; emit(this->flameDetected(true)); event_data.id = 0; } else if(event_data.id == 0 && flame_flag == 1) { qDebug()<<"flamedetection off"; flame_flag = 0; emit(this->flameDetected(false)); event_data.id = 0; } #endif //捕获key_2按下 ret = ioctl(fire_fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); if (ret == -1) { ret = -errno; fprintf(stderr, "Failed to issue %s (%d), %s\n", "GPIOHANDLE_GET_LINE_VALUES_IOCTL", ret, strerror(errno)); exit(ret); } //qDebug() << data.values[0]; if(data.values[0] ==1&&flame_flag==0) { emit(this->flameDetected()); flame_flag = 1; //qDebug()<<"flame on"; } else flame_flag = 0; } private: struct gpiohandle_request req; struct gpiohandle_data data; struct gpiochip_info chip_info; struct gpioevent_request event_req; struct gpioevent_data event_data; struct gpiod_chip *gpiochip5; struct gpiod_line *gpioline5_7; int key_1_fd; //设备文件描述符 int key_2_fd; int key_3_fd; int light_trigger_fd; int people_fd; int fire_fd; QTimer * fs_timer; }; #endif //ENV_H ------------------------------------------------------- fsmpFan.h: #ifndef FAN_H #define FAN_H /*************************************************************************** * * 类名:fsmpFan * 功能说明:扩展板 风扇控制 * 公有函数: * fsmpFan() * void start(void) 开启风扇) * void stop(void) 关闭风扇 * void setSpeed(int speed) 设置风扇速度(0-255) * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> class fsmpFan:public QObject{ Q_OBJECT public: explicit fsmpFan(QObject *parent = nullptr):QObject(parent) { const char *device = "/sys/class/hwmon/hwmon1/pwm1"; fan_fd = ::open(device,O_WRONLY|O_TRUNC); if(fan_fd < 0) { perror("open fan"); return; } fan_speed = 0; }; ~fsmpFan(){ ::close(fan_fd); } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ void stop(void) { write(fan_fd,"0",strlen("0")); } /* * Description: start设备 * input: null * output: null * return: 成功true/失败false */ void start(void) { char speedstr[100] = {0}; sprintf(speedstr, "%d", fan_speed); write(fan_fd, speedstr, strlen(speedstr)); } /* * Description: 控制风扇转速 * intput: speed 转速 * output: null * return: null */ void setSpeed(int speed) { fan_speed = speed%255; } private: int fan_fd; //设备文件描述符 int fan_speed; }; #endif // FAN_H ------------------------------------------------------- fsmpLeds.h: #ifndef LED_H #define LED_H /*************************************************************************** * * 类名:fsmpLeds * 功能说明:扩展板 3颗灯泡 * 公有函数: * fsmpLeds() * bool on(lednum x) 开灯 lednum: fsmpLeds::LED1/fsmpLeds::LED2/fsmpLeds::LED3 * bool off(lednum x) 关灯 lednum: fsmpLeds::LED1/fsmpLeds::LED2/fsmpLeds::LED3 * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> class fsmpLeds:public QObject{ Q_OBJECT public: enum lednum{ LED1, LED2, LED3 }; explicit fsmpLeds(QObject *parent = nullptr) :QObject(parent) { led_fd1 = ::open("/sys/class/leds/led1/brightness",O_WRONLY|O_TRUNC); if(led_fd1 < 0) { perror("open led1"); return ; } led_fd2 = ::open("/sys/class/leds/led2/brightness",O_WRONLY|O_TRUNC); if(led_fd2 < 0) { perror("open led2"); return ; } led_fd3 = ::open("/sys/class/leds/led3/brightness",O_WRONLY|O_TRUNC); if(led_fd3 < 0) { perror("open led3"); return ; } } ~fsmpLeds() { ::close(led_fd1); ::close(led_fd2); ::close(led_fd3); } /* * Description: 开启设备,默认/sys/class/leds/led1/brightness * input: lednum * output: null * return: 成功true/失败false */ bool on(lednum x) { int fd; if(x == LED1) fd = led_fd1; else if(x == LED2) fd = led_fd2; else if(x == LED3){ fd = led_fd3; } int ret = write(fd,"1",1); if(ret < 0) { return false; } return true; } /* * Description: 关闭设备 * input: null * output: null * return: 成功true/失败false */ bool off(lednum x) { int fd; if(x == LED1) fd = led_fd1; else if(x == LED2) fd = led_fd2; else if(x == LED3){ fd = led_fd3; } int ret = write(fd,"0",1); if(ret < 0) { return false; } return true; } private: int led_fd1; //设备文件描述符 int led_fd2; //设备文件描述符 int led_fd3; //设备文件描述符 }; #endif // LED_H ------------------------------------------------------- fsmpLight.h: #ifndef LIGHT_H #define LIGHT_H /*************************************************************************** * * 类名:fsmpLight * 功能说明:扩展板 光照强度检测 * 公有函数: * fsmpLight() * double getValue(void) 获取光照强度 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <QDebug> class fsmpLight:public QObject{ Q_OBJECT public: explicit fsmpLight(QObject *parent = nullptr) :QObject(parent) { light_fd = ::open("/sys/bus/iio/devices/iio:device1/in_illuminance_input",O_RDONLY|O_NONBLOCK); if(light_fd < 0) { perror("open"); return; } } ~fsmpLight() { ::close(light_fd); } /* * Description: 获取光照强度 * input: null * output: null * return: current light */ double getValue(void) { char buf[10] = {0}; int ret = read(light_fd,buf,10); if(ret < 0) { perror("read"); return false; } double num; sscanf(buf, "%lf", &num); lseek(light_fd, 0, SEEK_SET); return num; } private: int light_fd; //设备文件描述符 }; #endif // LIGHT_H ------------------------------------------------------- fsmpProximity.h: #ifndef FSMPPROXIMITY_H #define FSMPPROXIMITY_H /*************************************************************************** * * 类名:fsmpProximity * 功能说明:扩展板 红外接近传感器(和光照传感器一起) * 公有函数: * fsmpProximity() * double getValue(void) 获取接近情况(0-2048越接近数据越大) * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <QDebug> class fsmpProximity:public QObject{ Q_OBJECT public: explicit fsmpProximity(QObject *parent = nullptr) :QObject(parent) { proximity_fd = ::open("/sys/bus/iio/devices/iio:device1/in_proximity_raw",O_RDONLY|O_NONBLOCK); if(proximity_fd < 0) { perror("open"); return; } } ~fsmpProximity() { ::close(proximity_fd); } /* * Description: 获取distence * input: null * output: null * return: current light */ int getValue(void) { char buf[10] = {0}; int ret = read(proximity_fd,buf,10); if(ret < 0) { perror("read"); return false; } int num; sscanf(buf, "%d", &num); lseek(proximity_fd, 0, SEEK_SET); return num; } private: int proximity_fd; //设备文件描述符 }; #endif // FSMPPROXIMITY_H ------------------------------------------------------- fsmpSevensegLed.h: #ifndef FSMPSEVENSEGLED_H #define FSMPSEVENSEGLED_H /*************************************************************************** * * 类名:fsmpSevensegLed * 功能说明:扩展板 七段数码管 * 公有函数: * fsmpSevensegLed() * void display(int value) 显示4位以内整数 * void display(const char *str) 显示4位字符,注:仅支持 a、b、c、d、e * * 信号: * 无 * * *************************************************************************/ #include <stdint.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <fcntl.h> #include <sys/ioctl.h> #include #include #include <QThread> #include <stdlib.h> #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) class fsmpSevensegLed:public QThread{ Q_OBJECT public: explicit fsmpSevensegLed(QObject *parent = nullptr) :QThread(parent) { memset(data, 0, sizeof(data)); device = "/dev/spidev0.0"; bits = 8; speed = 400000; delay = 0; } void display(int value) { data[3] = value%10; data[2] = value/10%10; data[1] = value/100%10; data[0] = value/1000%10; } //"abcde" void display(const char *str) { data[3] = (strlen(str)-1 >= 0)?(str[strlen(str)-1] - 'a')+10:0; data[2] = (strlen(str)-2 >= 0)?(str[strlen(str)-2] - 'a')+10:0; data[1] = (strlen(str)-3 >= 0)?(str[strlen(str)-3] - 'a')+10:0; data[0] = (strlen(str)-4 >= 0)?(str[strlen(str)-4] - 'a')+10:0; } private: void run() { int ret = 0; int fd; fd = open(device, O_RDWR); //打开设备文件 if (fd < 0) pabort("can't open device"); /* * spi mode //设置spi设备模式 */ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); //写模式 if (ret == -1) pabort("can't set spi mode"); /* * bits per word //设置每个字含多少位 */ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); //写每个字含多少位 if (ret == -1) pabort("can't set bits per word"); /* * max speed hz //设置速率 */ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); //写速率 if (ret == -1) pabort("can't set max speed hz"); //打印模式,每字多少位和速率信息 printf("spi mode: %d\n", mode); printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); //transfer(fd); //传输测试 int i = 0; int pos = 0; unsigned char buf[2]; while(1) { pos = 1 << (i % 4); buf[0] = pos; buf[1] = num[data[i]]; if (write(fd, buf, 2) < 0) perror("write"); i++; if (i == 4) { i = 0; } usleep(3500); } } static void pabort(const char *s) { perror(s); abort(); } const char *device; uint8_t mode; uint8_t bits; uint32_t speed; uint16_t delay; int data[4]; unsigned char num[20] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; }; #endif // FSMPSEVENSEGLED_H ------------------------------------------------------- fsmpTempHum.h: #ifndef TEMPHUM_H #define TEMPHUM_H /*************************************************************************** * * 类名:fsmpTempHum * 功能说明:扩展板 温度湿度 * 公有函数: * fsmpTempHum() * double temperature(void) 提取温度 * double humidity(void) 提取湿度 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <stdint.h> #include <QDebug> class fsmpTempHum:public QObject{ Q_OBJECT public: explicit fsmpTempHum(QObject *parent = nullptr) :QObject(parent) { } double temperature(void) { int temp_raw = 0; int temp_offset = 0; float temp_scale = 0; open_device_int("iio:device0","in_temp_raw",&temp_raw); open_device_int("iio:device0","in_temp_offset",&temp_offset); open_device_float("iio:device0","in_temp_scale",&temp_scale); return (temp_raw + temp_offset) * temp_scale / 1000; } double humidity(void) { int hum_raw = 0; int hum_offset = 0; float hum_scale = 0; open_device_int("iio:device0","in_humidityrelative_raw",&hum_raw); open_device_int("iio:device0","in_humidityrelative_offset",&hum_offset); open_device_float("iio:device0","in_humidityrelative_scale",&hum_scale); return (hum_raw + hum_offset) * hum_scale / 1000; } private: bool open_device_int(const char *device, const char *filename, int *val) { int ret = 0; int fd; char temp[128] = {0}; sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename); fd = open(temp,O_RDONLY|O_NONBLOCK); if(fd < 0) { perror("open"); return false; } char buf[10] = {0}; ret = read(fd,buf,sizeof(buf)); if(ret < 0) { perror("read"); return false; } sscanf(buf,"%d",val); ::close(fd); return true; } bool open_device_float(const char *device, const char *filename, float *val) { int ret = 0; int fd; char temp[128] = {0}; sprintf(temp, "/sys/bus/iio/devices/%s/%s", device, filename); fd = open(temp,O_RDONLY|O_NONBLOCK); if(fd < 0) { perror("open"); return false; } char buf[10] = {0}; ret = read(fd,buf,sizeof(buf)); if(ret < 0) { perror("read"); return false; } sscanf(buf,"%f",val); ::close(fd); return true; } private: int temp_hum_fd;; //设备文件描述符 }; #endif // TEMPHUM_H ------------------------------------------------------- fsmpVibrator.h: #ifndef VIBRATOR_H #define VIBRATOR_H /*************************************************************************** * * 类名:fsmpVibrator * 功能说明:扩展板 振动马达 * 公有函数: * fsmpVibrator() * bool setParameter(int strong_magnitude, int timems) 设置振动强度(0-0xffff)及时长(ms) * bool start(void) 启动马达 * bool stop(void) 停止马达 * * 信号: * 无 * * *************************************************************************/ #include <QObject> #include #include <string.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <QIODevice> #include <sys/ioctl.h> #include <QDebug> class fsmpVibrator:public QObject{ Q_OBJECT public: explicit fsmpVibrator(QObject *parent = nullptr) :QObject(parent) { vibrator_fd = ::open("/dev/input/event1", O_RDWR|O_NONBLOCK); if(vibrator_fd < 0) { perror("open vibrator"); } } ~fsmpVibrator() { ::close(vibrator_fd); } /* * Description:设置 * input:频率 * output:null * return:成功true/失败false */ bool setParameter(int strong_magnitude = 0xFFFF, int timems = 5000) { //qDebug()<<strong_magnitude<<timems; effect.type = FF_RUMBLE, effect.id = -1, effect.u.rumble.strong_magnitude = strong_magnitude; effect.u.rumble.weak_magnitude = 0; effect.replay.length = timems; effect.replay.delay = 0; if (ioctl(vibrator_fd, EVIOCSFF, &effect) < 0) { printf("Error creating new effect: %s\n", strerror(errno)); return false; } return true; } bool start(void) { struct input_event play = { .type = EV_FF, .code = (__U16_TYPE)effect.id, .value = 1 }; int ret = write(vibrator_fd, (const void*) &play, sizeof(play)); if(ret < 0) { perror("vibrator on"); return false; } //qDebug()<<"start"; return true; } bool stop(void) { struct input_event play = { .type = EV_FF, .code = (__U16_TYPE)effect.id, .value = 0 }; int ret = write(vibrator_fd, (const void*) &play, sizeof(play)); if(ret < 0) { perror("vibrator off"); return false; } //qDebug()<<"stop"; return true; } private: int vibrator_fd;//设备文件描述符 struct ff_effect effect; }; #endif // VIBRATOR_H ------------------------------------------------------- 项目目的: 在Linux下通过qtcreator编写后通过st-mp1构建部署到远程Linux主机后,在Stm32mp157开发板上能够控制本身的硬件同时也能同步控制华清远见元宇宙实验中心物联网仿真系统内的模拟硬件。并且通过Desktop Qt5.12.12 GCC64bit构建部署到Deploy Configuration时,能够控制Stm32mp157开发板上的硬件同时也能同步控制华清远见元宇宙实验中心物联网仿真系统内的模拟硬件。 设计要求: 1. 通过点击pb_connect(连接按钮)按钮可以连接到云端mqtt,连接成功则弹出小窗提示连接成功并自动绑定订阅与发布功能、连接失败则弹出小窗提示连接失败,弹出的小窗有一个确定键,点击确定关闭小窗。 2. 点击按钮pb_led0打开Stm32mp157开发板上的LD1灯且同步打开华清远见元宇宙实验中心物联网仿真系统内的电灯0,此时按钮pb_led0上的文本(初始化为led0_on)变更为led0_off。再次点击按钮pb_led0时关闭Stm32mp157开发板上的LD1灯且同步关闭华清远见元宇宙实验中心物联网仿真系统内的电灯0,此时按钮pb_led0上的文本(此时为led0_off)变更为led0_on。按钮pb_led1和pb_led2也是相同理论。 3. 点击按钮pb_feng打开Stm32mp157开发板上的风扇且同步打开华清远见元宇宙实验中心物联网仿真系统内的风扇,此时按钮pb_feng上的文本(初始化为feng_on)变更为feng_off。再次点击按钮pb_feng时关闭Stm32mp157开发板上的风扇且同步关闭华清远见元宇宙实验中心物联网仿真系统内的风扇,此时按钮pb_feng上的文本(此时为feng_off)变更为feng_on。 4. 点击按钮pb_buzzer打开Stm32mp157开发板上的蜂鸣器,此时按钮pb_buzzer上的文本(初始化为:蜂鸣器_on)变更为蜂鸣器_off。再次点击按钮pb_buzzer时关闭Stm32mp157开发板上的蜂鸣器,此时按钮pb_buzzer上的文本(此时为:蜂鸣器_off)变更为蜂鸣器_on。 5. 点击按钮pb_humiture时,打开Stm32mp157开发板上的温湿度传感器并将数据显示在textBrowser组件上。此时按钮pb_humiture上的文本(初始化为:温湿度_on)变更为温湿度_off。再次点击按钮pb_humiture时关闭Stm32mp157开发板上的温湿度传感器,此时按钮pb_humiture上的文本(此时为:温湿度_off)变更为温湿度_on。(需添加功能:打开Stm32mp157开发板上的温湿度传感器后,当温度超过30度时蜂鸣器会立即开启,低于30度或者直接点击按钮pb_buzzer都可关闭蜂鸣器) 6. 点击按钮pb_photosensitive时,打开Stm32mp157开发板上的光敏传感器并将数据显示在textBrowser组件上。此时按钮pb_photosensitive上的文本(初始化为:光敏_on)变更为光敏_off。再次点击按钮pb_photosensitive时关闭Stm32mp157开发板上的光敏传感器,此时按钮pb_photosensitive上的文本(此时为:光敏_off)变更为光敏_on。 7. 点击按钮pb_infrared时,打开Stm32mp157开发板上的人体红外传感器并将数据显示在textBrowser组件上。此时按钮pb_infrared上的文本(初始化为:人体红外_on)变更为人体红外_off。再次点击按钮pb_infrared时关闭Stm32mp157开发板上的人体红外传感器,此时按钮pb_infrared上的文本(此时为:人体红外_off)变更为人体红外_on。 8. 点击按钮pb_camera时打开Stm32mp157开发板上的摄像头并将采集到的图像在屏幕界面的右侧显示出来(目前项目中没有设计用于显示摄像头采集图像显示的组件,需要添加)。此时按钮pb_camera上的文本(初始化为:摄像头_on)变更为摄像头off。再次点击按钮pb_camera时关闭Stm32mp157开发板上的摄像头,此时按钮pb_camera上的文本(此时为:摄像头_off)摄像头_on,并关闭摄像头采集的图像显示界面。 结合以上代码及要求,进行完整详细的项目开发,如有需要可以添加项目结构内缺失的文件(项目结构内缺失硬件的.cpp文件),硬件.h文件不可进行修改。整合后将项目的所有文件发我,让我复制粘贴就能直接使用

<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <rect> <x>0</x> <y>0</y> <width>800</width> <height>600</height> </rect> <string>MainWindow</string> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QPlainTextEdit" name="plainTextEdit"/> </item> </layout> </widget> <widget class="QStatusBar" name="statusbar"/> <widget class="QMenuBar" name="menubar"> <rect> <x>0</x> <y>0</y> <width>800</width> <height>29</height> </rect> <widget class="QMenu" name="FileMenu"> <string>文件</string> <addaction name="NewFile"/> <addaction name="OpenFile"/> <addaction name="SaveFile"/> <addaction name="SaveAsFile"/> <addaction name="ExitFile"/> </widget> <widget class="QMenu" name="menu_2"> <string>编辑</string> <addaction name="CutAct"/> <addaction name="CopyAct"/> <addaction name="PasteAct"/> <addaction name="FontAct"/> </widget> <addaction name="FileMenu"/> <addaction name="menu_2"/> </widget> <action name="NewFile"> <string>新建标签页</string> </action> <action name="action_2"> <string>新建窗口</string> </action> <action name="OpenFile"> <string>打开</string> </action> <action name="action_4"> <string>最近使用</string> </action> <action name="SaveFile"> <string>保存</string> </action> <action name="SaveAsFile"> <string>另存为</string> </action> <action name="action_7"> <string>全部保存</string> </action> <action name="action_8"> <string>关闭选项卡</string> </action> <action name="action_9"> <string>关闭窗口</string> </action> <action name="ExitFile"> <string>退出</string> </action> <action name="Cut"> <string>撤销</string> </action> <action name="CutAct"> <string>剪切</string> </action> <action name="CopyAct"> <string>复制</string> </action> <action name="PasteAct"> <string>粘贴</string> </action> <action name="action_15"> <string>删除</string> </action> <action name="action_16"> <string>查找</string> </action> <action name="action_17"> <string>查找下一个</string> </action> <action name="action_18"> <string>查找上一个</string> </action> <action name="action_19"> <string>替换</string> </action> <action name="action_20"> <string>全选</string> </action> <action name="action_21"> <string>日期/时间</string> </action> <action name="FontAct"> <string>字体</string> </action> <action name="action_23"> <string>缩放</string> </action> <action name="action_24"> <string>状态栏</string> </action> <action name="action_25"> <string>自动换行 </string> </action> </widget> <resources/> <connections/> </ui> ui部分如上 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QTextEdit> #include <QFileDialog> #include <QMessageBox> #include <QFontDialog> #include <QCloseEvent> #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); public slots: void newFile(); void openFile(); bool saveFile(); bool saveAs(); void setFont(); private: Ui::MainWindow *ui; void createActions(); void createMenus(); void createToolBars(); }; #endif // MAINWINDOW_H mainwindow.h部分如上 #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }main.cpp如上 #include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); //信号处理函数 connect(ui->OpenFile,&QAction::triggered,this,&MainWindow::openFile); } MainWindow::~MainWindow() { delete ui; } void MainWindow::openFile() { qInfo() << "打开文件"; } void MainWindow::newFile() { } bool MainWindow::saveFile() { } bool MainWindow::saveAs() { } void MainWindow::setFont() { } void MainWindow::createActions() { } void MainWindow::createMenus() { } void MainWindow::createToolBars() { }帮我完成mainwindows.cpp代码的编写,使其能在qt上运行

#include "mainwindow.h" #include <QApplication> #include <windows.h> #include <wtsapi32.h> #include <QLibrary> typedef BOOL(WINAPI *WTSSendMessageFunc)(HANDLE, DWORD, LPWSTR, DWORD, LPWSTR, DWORD, DWORD, LPDWORD, BOOL); int main(int argc, char *argv[]) { QApplication a(argc, argv); // 加载wtsapi32.dll QLibrary lib("wtsapi32.dll"); // 判断是否加载成功 if (!lib.load()) { QMessageBox::warning(NULL, "Warning", QString("Failed to load wtsapi32.dll: %1").arg(lib.errorString())); return 1; } // 获取函数指针 WTSSendMessageFunc WTSSendMessage = (WTSSendMessageFunc)lib.resolve("WTSSendMessageW"); if (WTSSendMessage == NULL) { QMessageBox::warning(NULL, "Warning", QString("Failed to resolve WTSSendMessageW: %1").arg(lib.errorString())); return 1; } // 获取当前会话ID DWORD dwSessionId = WTSGetActiveConsoleSessionId(); if (dwSessionId == 0xFFFFFFFF) { QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("获取会话ID失败!")); return -1; } // 获取当前会话令牌 HANDLE hToken = NULL; if (!WTSQueryUserToken(dwSessionId, &hToken)) { QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("获取用户令牌失败!")); return -1; } // 创建互斥量,确保程序只能运行一个实例 HANDLE mutex = ::CreateMutex(Q_NULLPTR, true, (LPCWSTR)qApp->applicationName().toStdWString().c_str()); if (!mutex) { QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("创建互斥量失败!")); CloseHandle(hToken); return -1; } if (GetLastError() == ERROR_ALREADY_EXISTS) { QMessageBox waringBox(QMessageBox::Warning, QStringLiteral("警告"), QStringLiteral("程序[文本数据同步客户端]只能运行一个!")); waringBox.setButtonText(QMessageBox::Ok, QStringLiteral("确定")); waringBox.setStandardButtons(QMessageBox::Ok); waringBox.exec(); ::CloseHandle(mutex); CloseHandle(hToken); return 0; } // 创建新进程,确保程序在当前会话中运行 STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.lpDesktop = (LPWSTR)L"winsta0\\default"; PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); if (!CreateProcessAsUser(hToken, NULL, (LPWSTR)qApp->applicationFilePath().toStdWString().data(), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { QMessageBox::warning(nullptr, QStringLiteral("错误"), QStringLiteral("创建进程失败!")); CloseHandle(mutex); CloseHandle(hToken); return -1; } // 关闭会话令牌和新进程句柄 CloseHandle(hToken); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); // 释放互斥量 ::ReleaseMutex(mutex); // 启动主窗口 MainWindow w; w.show(); return a.exec(); } 在以上代码中会提示:"获取用户令牌失败!",导致无法打开程序,这是什么原因,并给我解决办法

#include <QApplication> #include <QLockFile> #include <QDir> #include <QLocalServer> #include <QLocalSocket> #include <QMessageBox> #include "mainwindow.h" // 主窗口头文件 // 自定义全局唯一标识(根据应用特征修改) const QString SERVER_NAME = "MyCompany.MyApp.InstanceControl"; const QString LOCK_FILE_NAME = "MyApp.lock"; int main(int argc, char *argv[]) { QApplication app(argc, argv); /*------------------------------------------- * 第一步:创建跨平台锁文件检测 * 作用:防止多实例同时运行 *------------------------------------------*/ QLockFile lockFile(QDir::temp().absoluteFilePath(LOCK_FILE_NAME)); // 尝试获取文件锁(等待100ms) if (!lockFile.tryLock(100)) { /*------------------------------------- * 检测到已有实例运行时: * 1. 尝试连接到已有实例的本地服务 * 2. 发送激活指令 * 3. 主动退出新实例 *-------------------------------------*/ QLocalSocket socket; socket.connectToServer(SERVER_NAME); // 连接超时设置500ms if (socket.waitForConnected(500)) { // 发送激活指令(协议可自定义) socket.write("ACTIVATE_WINDOW"); socket.flush(); socket.waitForBytesWritten(300); } else { // 连接失败时的备用提示方案 QMessageBox::warning(nullptr, "提示", "程序已在运行且无法唤醒!"); } return EXIT_FAILURE; // 退出新实例 } /*------------------------------------------- * 第二步:创建本地Socket服务 * 作用:接收新实例的激活请求 *------------------------------------------*/ QLocalServer server; // 删除可能存在的旧服务(重要!) QLocalServer::removeServer(SERVER_NAME); if (!server.listen(SERVER_NAME)) { qCritical() << "本地服务创建失败:" << server.errorString(); return EXIT_FAILURE; } /*------------------------------------------- * 第三步:初始化主窗口 *------------------------------------------*/ MainWindow w; w.show(); /*------------------------------------------- * 第四步:建立消息处理机制 * 当接收到激活指令时执行窗口唤醒 *------------------------------------------*/ QObject::connect(&server, &QLocalServer::newConnection, [&]() { // 获取客户端连接 QLocalSocket *client = server.nextPendingConnection(); // 设置消息处理回调 QObject::connect(client, &QLocalSocket::readyRead, [&w, client]() { // 读取完整消息 const QString msg = QString::fromUtf8(client->readAll()).trimmed(); if (msg == "ACTIVATE_WINDOW") { // 窗口唤醒优化逻辑 if (w.isMinimized()) { w.showNormal(); // 从最小化恢复 } w.raise(); // 置顶窗口 w.activateWindow(); // 激活窗口 } client->deleteLater(); // 释放连接 }); }); /*------------------------------------------- * 第五步:程序退出时的清理工作 *------------------------------------------*/ QObject::connect(&app, &QApplication::aboutToQuit, [&]() { server.close(); // 关闭服务 lockFile.unlock(); // 释放文件锁 QLocalServer::removeServer(SERVER_NAME); // 清理服务 }); return app.exec(); } 优化

void wizard::WsfEditor::SetTextFormat(size_t aStart, size_t aCount, const QTextCharFormat& aFmt) { // 将字节位置转换为Qt字符位置以正确处理中文字符 size_t qtStart = BytePosToQtPos(aStart); size_t qtEnd = BytePosToQtPos(aStart + aCount); size_t qtCount = qtEnd - qtStart; size_t end = std::min(qtStart + qtCount, mCurrentStylePos + mCurrentStyleLength); if (end >= mCurrentStylePos) { for (size_t i = std::max(mCurrentStylePos, qtStart) - mCurrentStylePos; i < end - mCurrentStylePos; ++i) { mFormatChanges[ut::cast_to_int(i)] = aFmt; } } } void wizard::WsfEditor::MergeTextFormat(size_t aStart, size_t aCount, const QTextCharFormat& aFmt) { // 将字节位置转换为Qt字符位置以正确处理中文字符 size_t qtStart = BytePosToQtPos(aStart); size_t qtEnd = BytePosToQtPos(aStart + aCount); size_t qtCount = qtEnd - qtStart; size_t end = std::min(qtStart + qtCount, mCurrentStylePos + mCurrentStyleLength); if (end >= mCurrentStylePos) { for (size_t i = std::max(mCurrentStylePos, qtStart) - mCurrentStylePos; i < end - mCurrentStylePos; ++i) { mFormatChanges[ut::cast_to_int(i)].merge(aFmt); } } } size_t wizard::WsfEditor::BytePosToQtPos(size_t aBytePos) { // 如果没有中文字符,字节位置和字符位置是相同的 if (aBytePos == 0) return 0; // 获取当前整个文档内容 QString fullText = toPlainText(); // 将文档转换为UTF-8字节流 std::string utf8Text = ToAscii(fullText); // 如果字节位置超出范围,返回文档末尾 if (aBytePos >= utf8Text.size()) { return fullText.length(); } // 使用二分查找找到对应的Qt字符位置 int left = 0, right = fullText.length(); while (left < right) { int mid = (left + right) / 2; // 获取从开始到mid位置的Qt字符串 QString partialText = fullText.left(mid); std::string partialUtf8 = ToAscii(partialText); if (partialUtf8.size() < aBytePos) { left = mid + 1; } else { right = mid; } } return left; }bool wizard::TextSource::ReadSource(bool aAlwaysFullyReload) { bool loaded(false); UtPath::StatData statData; GetFilePath().Stat(statData); if (statData.mStatType == UtPath::cDIRECTORY) { return false; } if (statData.mStatType == UtPath::cFILE) { if (statData.mFileSizeBytes < (size_t)cMAXIMUM_FILE_SIZE) { // After first read, ensure the parser isn't running. if (mLoaded) { GetWorkspace()->WaitForAbortParsing(); } if (UtTextDocument::ReadFile(GetFilePath())) { SetDeleted(false); SetModified(false); bool requiresParse = GetProject()->SourceReloaded(this); if (requiresParse) { GetProject()->TriggerReparse(); } loaded = true; } } else { const QString msg("The file %1 is too large to open. (%2 MB)."); const QString filePath(QString::fromUtf8(mFilePath.GetSystemPath().c_str())); const double sizeMb = (statData.mFileSizeBytes / 1000000.0); QMessageBox::warning(nullptr, "File too large", msg.arg(filePath).arg(sizeMb)); if (mLoaded) { SetModified(false); Unload(); } loaded = false; } mFileSignature.Update(mFilePath); } else if (statData.mStatType == UtPath::cSTAT_ERROR) { Clear(); Insert(0, "\0", 1); // null terminator SetDeleted(true); SetModified(false); loaded = true; } if (!mViews.empty()) { ReloadEditor(*mViews[0]->mEditorPtr, false, true, aAlwaysFullyReload); } if (loaded) { mPendingChanges.clear(); mAppliedChanges.clear(); } mLoaded = loaded; return loaded; }void wizard::TextSource::ReloadEditor(Editor& aEditor, bool aInitialLoad, bool aForceUnmodified, bool aForceReload) { aEditor.BeginNonUserAction(); if (aInitialLoad || aForceReload) { // Copy text to scintilla char* textPtr = GetText().GetPointer(0); aEditor.BeginNonUserAction(); aEditor.document()->setPlainText(QString::fromUtf8(textPtr)); QTextCursor cur = aEditor.textCursor(); cur.setPosition(0); aEditor.setTextCursor(cur); aEditor.EndNonUserAction(); if (aInitialLoad) { aEditor.document()->clearUndoRedoStacks(); aEditor.document()->setModified(false); } } else { // Diff this text document with scintilla's copy. Apply only the changes. std::string oldText = aEditor.ToAscii(aEditor.ToPlainText()); QVector<TextSourceChange> changes; DiffDocuments(oldText.c_str(), GetPointer(), changes); if (!changes.empty()) { int firstChangePos = -1; QTextCursor cur = aEditor.textCursor(); cur.beginEditBlock(); for (int i = 0; i < changes.size(); ++i) { const TextSourceChange& change = changes[i]; if (i == 0) firstChangePos = ut::cast_to_int(change.mPos); ApplyChangeToQt(changes[i], cur); } cur.endEditBlock(); if (!aForceUnmodified) { SetModified(true, true); } // scroll to first change if (firstChangePos != -1) { QTextCursor cur = aEditor.textCursor(); cur.setPosition(firstChangePos); aEditor.setTextCursor(cur); aEditor.centerCursor(); } } if (!mModified) { // aEditor.SendScintilla(SCI_SETSAVEPOINT); } } aEditor.EndNonUserAction(); aEditor.ReloadComplete(); }void wizard::TextSource::SaveAs() { UtPath dir = GetFilePath(); dir.Up(); QFileDialog dlg(nullptr, "Save File As", dir.GetSystemPath().c_str(), "*.*"); dlg.setDefaultSuffix("txt"); dlg.selectFile(GetFileName().c_str()); dlg.setAcceptMode(QFileDialog::AcceptSave); dlg.setFileMode(QFileDialog::AnyFile); if (dlg.exec()) { QStringList selFiles = dlg.selectedFiles(); if (selFiles.length() == 1) { // Ensure the source is ready WaitForSourceModifications(); std::string newFilePath = selFiles[0].toUtf8().toStdString(); std::ofstream outfile(newFilePath.c_str(), std::ios::binary); while (!outfile) { std::stringstream ss; ss << "Could not save file " + newFilePath + ", check that the file/directory is writable."; int bn = QMessageBox::warning(nullptr, "Could not save", ss.str().c_str(), "Retry", "Cancel"); if (bn != 0) { break; } } if (outfile) { WriteFile(outfile); outfile.close(); UtPath newFile(newFilePath); if (newFile.Stat() == UtPath::cFILE) { // WIZARD_TODO: Open the file for the user? // GetProject()->AddTransientFile(newFile); } emit TextSourceSignals::GetInstance().requestBackup(); } } } } void wizard::TextSource::CopyPathToClipboard() { QApplication::clipboard()->setText(QString::fromUtf8(GetSystemPath().c_str())); }void wizard::TextSource::ApplyChangeToQt(const TextSourceChange& aChange, QTextCursor& aCursor) { if (aCursor.document()->toPlainText().size() < static_cast<int>(aChange.mPos)) { // Adding at the end of the document aCursor.movePosition(QTextCursor::End); aCursor.insertText("\n"); } aCursor.setPosition(ut::cast_to_int(aChange.mPos)); aCursor.setPosition(ut::cast_to_int(aChange.mPos + aChange.mCharsRemoved), QTextCursor::KeepAnchor); // 正确处理UTF-8字符串到Qt的转换 aCursor.insertText(QString::fromUtf8(aChange.mText.c_str())); } void wizard::TextSource::FindIncludeLocations() { if (GetProject()) { GetProject()->FindIncludes(this); } } void wizard::TextSource::SaveAndStore() { SaveWithNotifications(); emit TextSourceSignals::GetInstance().requestBackup(); } void wizard::TextSource::BrowseContainingFolder() { UtPath path = mFilePath; path.Up(); QString pathStr("file:///"); pathStr += QString::fromUtf8(path.GetSystemPath().c_str()); QDesktopServices::openUrl(QUrl(pathStr)); }// 将Qt字符位置转换为对应的UTF-8字节位置 size_t wizard::Editor::QtPosToUtf8Pos(int aQtPos) { if (aQtPos <= 0) return 0; // 获取从开始到指定位置的文本 QTextCursor cur(document()); cur.setPosition(0); cur.setPosition(aQtPos, QTextCursor::KeepAnchor); QString partialText = cur.selectedText(); // 转换为UTF-8并返回字节长度 std::string utf8Text = ToAscii(partialText); return utf8Text.size(); } // 将UTF-8字节位置转换为对应的Qt字符位置 int wizard::Editor::Utf8PosToQtPos(size_t aUtf8Pos) { if (aUtf8Pos == 0) return 0; QString fullText = toPlainText(); std::string fullUtf8 = ToAscii(fullText); if (aUtf8Pos >= fullUtf8.size()) { return fullText.length(); } // 使用二分查找找到对应的Qt位置 int left = 0, right = fullText.length(); while (left < right) { int mid = (left + right) / 2; size_t midUtf8Pos = QtPosToUtf8Pos(mid); if (midUtf8Pos < aUtf8Pos) { left = mid + 1; } else { right = mid; } } return left; } std::string wizard::Editor::ToAscii(const QString& aText) { // 处理段落分隔符,然后转换为UTF-8 QString processedText = aText; processedText.replace(QChar(0x2029), QChar('\n')); // paragraph separator // 直接使用UTF-8编码保持中文字符 return processedText.toUtf8().toStdString(); } void wizard::Editor::DocContentsChange(int aFrom, int aCharsRemoves, int aCharsAdded) { if (mNonUserAction > 0) { return; } // 简化处理:对于任何变化,都重新同步整个文档内容 // 这避免了复杂的位置转换问题,特别是中英文混合的情况 mSourcePtr->HandleDelete(0, 0x0fffffff); QTextCursor cur(document()); cur.setPosition(0); cur.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); QString newText = cur.selectedText(); // Convert to UTF-8 representation std::string text = ToAscii(newText); // 使用UTF-8字符串的实际字节长度 mSourcePtr->HandleInsert(0, text.size(), text.c_str()); }void wizard::ProjectWorkspace::NewProject() { // Use the location of the last opened project // otherwise use the user's home directory // else use the location of the executable QString newLocationDir = QDir::currentPath(); if (!QDir::current().exists()) { // Absolute path of the user's home directory newLocationDir = QDir::toNativeSeparators(QDir::homePath()); // Home directory // openLocationDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); // Documents directory if (newLocationDir.isEmpty()) { newLocationDir = QString::fromStdString(UtPath::GetExePath().GetSystemPath()); } } // Get the new project file name QString fileName = QFileDialog::getSaveFileName(nullptr, "New Project", newLocationDir, "AFSIM Project (*.afproj)"); if (!fileName.isEmpty() && // set the working directory to the new project's directory wizRunMgr.SetWorkingDirectoryToProject(fileName)) { // 使用UTF-8编码处理文件名 std::string utf8FileName = fileName.toUtf8().toStdString(); UtPath fileNamePath(utf8FileName); UtPath filePath = fileNamePath; filePath.Up(); Project* projectPtr = new Project(this); projectPtr->SetProjectLocation(filePath.GetSystemPath(), fileNamePath); } }wizard::Runner::Runner(int& argc, char* argv[], const char* aCompanyStr, const char* aCompanyDomainStr, const char* aProductNameStr, const char* aProductVersionStr) { // Get the executable path // Trim the name of the executable mBinDir = UtPath::GetExePath(); mBinDir.Up(); QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); mApp = ut::make_unique<QApplication>(argc, argv); // 设置UTF-8编码支持中文 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); #endif mApp->setQuitOnLastWindowClosed(true); mApp->setWindowIcon(QIcon(":icons/wizard_logo_icon.png")); qApp->setOrganizationName(aCompanyStr); qApp->setOrganizationDomain(aCompanyDomainStr); qApp->setApplicationName(aProductNameStr); qApp->setApplicationDisplayName(aProductNameStr); qApp->setApplicationVersion(aProductVersionStr); }void Scanner::Init() { NewTokCb = nullptr; mNewTokenDataPtr = nullptr; EOL = '\n'; eofSym = 0; // ***Declarations Begin maxT = 58; noSym = 58; int i; for (i = 65; i <= 90; ++i) start.set(i, 1); for (i = 95; i <= 95; ++i) start.set(i, 1); for (i = 97; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 31); for (i = 34; i <= 34; ++i) start.set(i, 7); start.set(46, 32); start.set(39, 9); start.set(59, 13); start.set(40, 14); start.set(41, 15); start.set(61, 33); start.set(33, 43); start.set(62, 44); start.set(60, 45); start.set(43, 34); start.set(45, 35); start.set(38, 20); start.set(124, 22); start.set(125, 24); start.set(44, 25); start.set(42, 46); start.set(47, 47); start.set(123, 38); start.set(58, 39); start.set(94, 40); start.set(91, 41); start.set(93, 42); start.set(Buffer::EoF, -1); keywords.set("do", 26); keywords.set("if", 27); keywords.set("for", 28); keywords.set("foreach", 29); keywords.set("in", 30); keywords.set("else", 31); keywords.set("while", 32); keywords.set("break", 33); keywords.set("continue", 34); keywords.set("return", 35); keywords.set("null", 36); keywords.set("NULL", 37); keywords.set("true", 38); keywords.set("false", 39); keywords.set("string", 40); keywords.set("int", 41); keywords.set("double", 42); keywords.set("char", 43); keywords.set("bool", 44); keywords.set("global", 45); keywords.set("static", 46); keywords.set("extern", 47); // ***Declarations End tvalLength = 128; tval = new cocochar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**)(((char*)heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = nullptr; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { ut::log::fatal() << "Too small COCO_HEAP_BLOCK_SIZE."; exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); #if !COCO_USE_INLINE_BUFFER bool hasUtf8Bom = false; if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 == 0xBB && ch2 == 0xBF) { hasUtf8Bom = true; } else { // 不是UTF-8 BOM,回退到开始位置 buffer->SetPos(0); pos = -1; line = 1; col = 0; charPos = -1; NextCh(); } } // 默认启用UTF-8支持,无论是否有BOM // 这样可以支持没有BOM的UTF-8文件(包含中文的脚本文件) Buffer* oldBuf = buffer; buffer = new UTF8Buffer(buffer); if (hasUtf8Bom) { col = 0; charPos = -1; NextCh(); // 跳过BOM } else { // 重新开始读取,使用UTF8Buffer buffer->SetPos(0); pos = -1; line = 1; col = 0; charPos = -1; NextCh(); } delete oldBuf; oldBuf = nullptr; #endif pt = tokens = CreateToken(); // first token is a dummy }UsVal UsCtx::StringLiteral(UtScriptLanguage::Token* t) { std::string str(t->val + 1, t->val + t->len - 1); std::string unescapedStr; bool hasSlash = false; // 使用UTF-8安全的字符迭代 for (size_t i = 0; i < str.length(); ++i) { unsigned char c = static_cast<unsigned char>(str[i]); if (!hasSlash) { if (c == '\\') { hasSlash = true; } else { // 检查是否是UTF-8多字节字符的开始 if (c >= 0x80) // UTF-8多字节字符 { // 计算UTF-8字符的字节数 size_t utf8_len = 1; if ((c & 0xE0) == 0xC0) utf8_len = 2; // 110xxxxx else if ((c & 0xF0) == 0xE0) utf8_len = 3; // 1110xxxx else if ((c & 0xF8) == 0xF0) utf8_len = 4; // 11110xxx // 确保不会越界,并复制完整的UTF-8字符 if (i + utf8_len <= str.length()) { unescapedStr.append(str, i, utf8_len); i += utf8_len - 1; // -1因为for循环会++i } else { // 如果UTF-8字符不完整,按原样添加 unescapedStr += c; } } else { // ASCII字符,直接添加 unescapedStr += c; } } } else { switch (c) { case 'a': unescapedStr += '\a'; break; case 'b': unescapedStr += '\b'; break; case 'r': unescapedStr += '\r'; break; case 'f': unescapedStr += '\f'; break; case 'n': unescapedStr += '\n'; break; case 't': unescapedStr += '\t'; break; case 'v': unescapedStr += '\v'; break; case '\'': case '"': case '\\': unescapedStr += c; break; default: // 对于不认识的转义序列,保留反斜杠和字符 unescapedStr += '\\'; unescapedStr += c; break; } hasSlash = false; } } return CreateData(unescapedStr); }{ StatType fileType(cSTAT_ERROR); std::string sysPath = GetSystemPath(); #ifdef _WIN32 // 使用Unicode版本的文件检查 if (UtPathUnicode::FileExists(mPathString)) { fileType = cFILE; } else if (UtPathUnicode::DirectoryExists(mPathString)) { fileType = cDIRECTORY; } #else struct stat buff; if (0 == ::stat(sysPath.c_str(), &buff)) { if ((buff.st_mode & S_IFDIR) != 0) { fileType = cDIRECTORY; } else { fileType = cFILE; } } #endif return fileType; }// // CUI // // The Advanced Framework for Simulation, Integration, and Modeling (AFSIM) // // Copyright 2003-2015 The Boeing Company. All rights reserved. // // The use, dissemination or disclosure of data in this file is subject to // limitation or restriction. See accompanying README and LICENSE for details. // #include "UtPathUnicode.hpp" #include <sys/stat.h> #ifdef _WIN32 #include <io.h> #include <direct.h> #else #include <unistd.h> #include <sys/types.h> #include <dirent.h> #endif #ifdef _WIN32 std::wstring UtPathUnicode::Utf8ToWide(const std::string& aUtf8) { if (aUtf8.empty()) return std::wstring(); int wideSize = MultiByteToWideChar(CP_UTF8, 0, aUtf8.c_str(), -1, nullptr, 0); if (wideSize <= 0) return std::wstring(); std::wstring wide(wideSize - 1, 0); MultiByteToWideChar(CP_UTF8, 0, aUtf8.c_str(), -1, &wide[0], wideSize); return wide; } std::string UtPathUnicode::WideToUtf8(const std::wstring& aWide) { if (aWide.empty()) return std::string(); int utf8Size = WideCharToMultiByte(CP_UTF8, 0, aWide.c_str(), -1, nullptr, 0, nullptr, nullptr); if (utf8Size <= 0) return std::string(); std::string utf8(utf8Size - 1, 0); WideCharToMultiByte(CP_UTF8, 0, aWide.c_str(), -1, &utf8[0], utf8Size, nullptr, nullptr); return utf8; } std::string UtPathUnicode::AnsiToUtf8(const std::string& aAnsi) { if (aAnsi.empty()) return std::string(); // 先转换为宽字符 int wideSize = MultiByteToWideChar(CP_ACP, 0, aAnsi.c_str(), -1, nullptr, 0); if (wideSize <= 0) return aAnsi; std::wstring wide(wideSize - 1, 0); MultiByteToWideChar(CP_ACP, 0, aAnsi.c_str(), -1, &wide[0], wideSize); // 再转换为UTF-8 return WideToUtf8(wide); } #endif std::string UtPathUnicode::ToSystemPath(const std::string& aUtf8Path) { #ifdef _WIN32 // 在Windows上,将UTF-8路径转换为系统路径 // 对于文件系统操作,我们需要使用宽字符API return aUtf8Path; // 保持UTF-8格式,在具体的文件操作中转换 #else // 在Unix系统上,文件系统通常使用UTF-8 return aUtf8Path; #endif } std::string UtPathUnicode::FromSystemPath(const std::string& aSystemPath) { #ifdef _WIN32 // 假设系统路径可能是ANSI编码,转换为UTF-8 return AnsiToUtf8(aSystemPath); #else return aSystemPath; #endif } bool UtPathUnicode::FileExists(const std::string& aUtf8Path) { #ifdef _WIN32 std::wstring widePath = Utf8ToWide(aUtf8Path); DWORD attributes = GetFileAttributesW(widePath.c_str()); return (attributes != INVALID_FILE_ATTRIBUTES) && !(attributes & FILE_ATTRIBUTE_DIRECTORY); #else struct stat buffer; return (stat(aUtf8Path.c_str(), &buffer) == 0) && S_ISREG(buffer.st_mode); #endif } bool UtPathUnicode::DirectoryExists(const std::string& aUtf8Path) { #ifdef _WIN32 std::wstring widePath = Utf8ToWide(aUtf8Path); DWORD attributes = GetFileAttributesW(widePath.c_str()); return (attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY); #else struct stat buffer; return (stat(aUtf8Path.c_str(), &buffer) == 0) && S_ISDIR(buffer.st_mode); #endif } bool UtPathUnicode::CreateDirectory(const std::string& aUtf8Path) { #ifdef _WIN32 std::wstring widePath = Utf8ToWide(aUtf8Path); return CreateDirectoryW(widePath.c_str(), nullptr) != 0; #else return mkdir(aUtf8Path.c_str(), 0755) == 0; #endif } bool UtPathUnicode::DeleteFile(const std::string& aUtf8Path) { #ifdef _WIN32 std::wstring widePath = Utf8ToWide(aUtf8Path); return DeleteFileW(widePath.c_str()) != 0; #else return unlink(aUtf8Path.c_str()) == 0; #endif } size_t UtPathUnicode::GetFileSize(const std::string& aUtf8Path) { #ifdef _WIN32 std::wstring widePath = Utf8ToWide(aUtf8Path); WIN32_FILE_ATTRIBUTE_DATA fileInfo; if (GetFileAttributesExW(widePath.c_str(), GetFileExInfoStandard, &fileInfo)) { LARGE_INTEGER size; size.HighPart = fileInfo.nFileSizeHigh; size.LowPart = fileInfo.nFileSizeLow; return static_cast<size_t>(size.QuadPart); } return 0; #else struct stat buffer; if (stat(aUtf8Path.c_str(), &buffer) == 0) { return static_cast<size_t>(buffer.st_size); } return 0; #endif } 这些代码是为了在QPlainTextEdit中支持中文进行的所有修改,但是目前高亮和自动补全有问题,提供的文件是高亮和自动补全的cpp实现,请协助我修改代码,给出每个需要修改的函数的完整实现,不要省略不需要修改的代码

最新推荐

recommend-type

掌握XFireSpring整合技术:HELLOworld原代码使用教程

标题:“xfirespring整合使用原代码”中提到的“xfirespring”是指将XFire和Spring框架进行整合使用。XFire是一个基于SOAP的Web服务框架,而Spring是一个轻量级的Java/Java EE全功能栈的应用程序框架。在Web服务开发中,将XFire与Spring整合能够发挥两者的优势,例如Spring的依赖注入、事务管理等特性,与XFire的简洁的Web服务开发模型相结合。 描述:“xfirespring整合使用HELLOworld原代码”说明了在这个整合过程中实现了一个非常基本的Web服务示例,即“HELLOworld”。这通常意味着创建了一个能够返回"HELLO world"字符串作为响应的Web服务方法。这个简单的例子用来展示如何设置环境、编写服务类、定义Web服务接口以及部署和测试整合后的应用程序。 标签:“xfirespring”表明文档、代码示例或者讨论集中于XFire和Spring的整合技术。 文件列表中的“index.jsp”通常是一个Web应用程序的入口点,它可能用于提供一个用户界面,通过这个界面调用Web服务或者展示Web服务的调用结果。“WEB-INF”是Java Web应用中的一个特殊目录,它存放了应用服务器加载的Servlet类文件和相关的配置文件,例如web.xml。web.xml文件中定义了Web应用程序的配置信息,如Servlet映射、初始化参数、安全约束等。“META-INF”目录包含了元数据信息,这些信息通常由部署工具使用,用于描述应用的元数据,如manifest文件,它记录了归档文件中的包信息以及相关的依赖关系。 整合XFire和Spring框架,具体知识点可以分为以下几个部分: 1. XFire框架概述 XFire是一个开源的Web服务框架,它是基于SOAP协议的,提供了一种简化的方式来创建、部署和调用Web服务。XFire支持多种数据绑定,包括XML、JSON和Java数据对象等。开发人员可以使用注解或者基于XML的配置来定义服务接口和服务实现。 2. Spring框架概述 Spring是一个全面的企业应用开发框架,它提供了丰富的功能,包括但不限于依赖注入、面向切面编程(AOP)、数据访问/集成、消息传递、事务管理等。Spring的核心特性是依赖注入,通过依赖注入能够将应用程序的组件解耦合,从而提高应用程序的灵活性和可测试性。 3. XFire和Spring整合的目的 整合这两个框架的目的是为了利用各自的优势。XFire可以用来创建Web服务,而Spring可以管理这些Web服务的生命周期,提供企业级服务,如事务管理、安全性、数据访问等。整合后,开发者可以享受Spring的依赖注入、事务管理等企业级功能,同时利用XFire的简洁的Web服务开发模型。 4. XFire与Spring整合的基本步骤 整合的基本步骤可能包括添加必要的依赖到项目中,配置Spring的applicationContext.xml,以包括XFire特定的bean配置。比如,需要配置XFire的ServiceExporter和ServicePublisher beans,使得Spring可以管理XFire的Web服务。同时,需要定义服务接口以及服务实现类,并通过注解或者XML配置将其关联起来。 5. Web服务实现示例:“HELLOworld” 实现一个Web服务通常涉及到定义服务接口和服务实现类。服务接口定义了服务的方法,而服务实现类则提供了这些方法的具体实现。在XFire和Spring整合的上下文中,“HELLOworld”示例可能包含一个接口定义,比如`HelloWorldService`,和一个实现类`HelloWorldServiceImpl`,该类有一个`sayHello`方法返回"HELLO world"字符串。 6. 部署和测试 部署Web服务时,需要将应用程序打包成WAR文件,并部署到支持Servlet 2.3及以上版本的Web应用服务器上。部署后,可以通过客户端或浏览器测试Web服务的功能,例如通过访问XFire提供的服务描述页面(WSDL)来了解如何调用服务。 7. JSP与Web服务交互 如果在应用程序中使用了JSP页面,那么JSP可以用来作为用户与Web服务交互的界面。例如,JSP可以包含JavaScript代码来发送异步的AJAX请求到Web服务,并展示返回的结果给用户。在这个过程中,JSP页面可能使用XMLHttpRequest对象或者现代的Fetch API与Web服务进行通信。 8. 项目配置文件说明 项目配置文件如web.xml和applicationContext.xml分别在Web应用和服务配置中扮演关键角色。web.xml负责定义Web组件,比如Servlet、过滤器和监听器,而applicationContext.xml则负责定义Spring容器中的bean,包括数据源、事务管理器、业务逻辑组件和服务访问器等。 总之,通过上述整合使用原代码的知识点,可以深入理解XFire与Spring框架的结合使用,以及如何开发和部署基本的Web服务。这些技术知识有助于进行更高层次的Web服务开发,以及在复杂的IT环境中灵活运用各种框架和工具。
recommend-type

【Unity2018汉化大揭秘】:一步到位优化中文用户体验

# 摘要 本论文详细介绍了Unity2018汉化项目的实施过程,从理论准备到实践步骤,再到后期的测试与优化,最终分享了汉化经验和心得。首先,强调了汉化项目对于用户体验提升和产品国际化的重要性,并分析了汉化资源的分类、识别与管理方法。接着,详细阐述了汉化工具的选择、脚本编写、资源手动调整等实践步骤,以及汉化质量测试、体验优化和项目维护更新的重要性。论文最后通过案例研究,分析了汉化中的挑战和应对策略,并预测了汉化技术未来的发展方向。整个汉化过程不仅涉及技术层面的操作,还包含了深入的理论研究和实践心得分享,对提升汉化项目的效率和质量具有指导意义。 # 关键字 Unity汉化;用户体验;国际化;资源
recommend-type

iPhone

<think>我们注意到用户意图不明确,但提到了“照片提取”和“其他功能帮助”。因此,我们需要通过搜索来获取关于iPhone照片提取的常见方法以及其他可能的功能帮助。由于用户问题比较宽泛,我们将重点放在照片提取上,因为这是明确提到的关键词。同时,我们也会考虑一些其他常用功能的帮助。首先,针对照片提取,可能涉及从iPhone导出照片、从备份中提取照片、或者从损坏的设备中恢复照片等。我们将搜索这些方面的信息。其次,关于其他功能帮助,我们可以提供一些常见问题的快速指南,如电池优化、屏幕时间管理等。根据要求,我们需要将答案组织为多个方法或步骤,并在每个步骤间换行。同时,避免使用第一人称和步骤词汇。由于
recommend-type

驾校一点通软件:提升驾驶证考试通过率

标题“驾校一点通”指向的是一款专门为学员考取驾驶证提供帮助的软件,该软件强调其辅助性质,旨在为学员提供便捷的学习方式和复习资料。从描述中可以推断出,“驾校一点通”是一个与驾驶考试相关的应用软件,这类软件一般包含驾驶理论学习、模拟考试、交通法规解释等内容。 文件标题中的“2007”这个年份标签很可能意味着软件的最初发布时间或版本更新年份,这说明了软件具有一定的历史背景和可能经过了多次更新,以适应不断变化的驾驶考试要求。 压缩包子文件的文件名称列表中,有以下几个文件类型值得关注: 1. images.dat:这个文件名表明,这是一个包含图像数据的文件,很可能包含了用于软件界面展示的图片,如各种标志、道路场景等图形。在驾照学习软件中,这类图片通常用于帮助用户认识和记忆不同交通标志、信号灯以及驾驶过程中需要注意的各种道路情况。 2. library.dat:这个文件名暗示它是一个包含了大量信息的库文件,可能包含了法规、驾驶知识、考试题库等数据。这类文件是提供给用户学习驾驶理论知识和准备科目一理论考试的重要资源。 3. 驾校一点通小型汽车专用.exe:这是一个可执行文件,是软件的主要安装程序。根据标题推测,这款软件主要是针对小型汽车驾照考试的学员设计的。通常,小型汽车(C1类驾照)需要学习包括车辆构造、基础驾驶技能、安全行车常识、交通法规等内容。 4. 使用说明.html:这个文件是软件使用说明的文档,通常以网页格式存在,用户可以通过浏览器阅读。使用说明应该会详细介绍软件的安装流程、功能介绍、如何使用软件的各种模块以及如何通过软件来帮助自己更好地准备考试。 综合以上信息,我们可以挖掘出以下几个相关知识点: - 软件类型:辅助学习软件,专门针对驾驶考试设计。 - 应用领域:主要用于帮助驾考学员准备理论和实践考试。 - 文件类型:包括图片文件(images.dat)、库文件(library.dat)、可执行文件(.exe)和网页格式的说明文件(.html)。 - 功能内容:可能包含交通法规知识学习、交通标志识别、驾驶理论学习、模拟考试、考试题库练习等功能。 - 版本信息:软件很可能最早发布于2007年,后续可能有多个版本更新。 - 用户群体:主要面向小型汽车驾照考生,即C1类驾照学员。 - 使用方式:用户需要将.exe安装文件进行安装,然后根据.html格式的使用说明来熟悉软件操作,从而利用images.dat和library.dat中的资源来辅助学习。 以上知识点为从给定文件信息中提炼出来的重点,这些内容对于了解“驾校一点通”这款软件的功能、作用、使用方法以及它的发展历史都有重要的指导意义。
recommend-type

【DFLauncher自动化教程】:简化游戏启动流程,让游戏体验更流畅

# 摘要 DFLauncher是一个功能丰富的游戏启动和管理平台,本论文将介绍其安装、基础使用、高级设置、社区互动以及插件开发等方面。通过对配置文件的解析、界面定制、自动化功能的实现、高级配置选项、安全性和性能监控的详细讨论,本文阐述了DFLauncher如何帮助用户更高效地管理和优化游戏环境。此外,本文还探讨了DFLauncher社区的资源分享、教育教程和插件开发等内容,
recommend-type

自适应卡尔曼滤波是什么意思

<think>嗯,用户这次想深入了解自适应卡尔曼滤波(AKF)的概念和原理。从对话历史看,用户之前研究过相机自动对焦系统的降噪技术,其中提到过自适应卡尔曼滤波的应用场景。用户可能是个工程师或研究者,正在探索信号处理在具体场景的实现细节。 用户提供的三篇参考文献很有价值:[1]是基础理论综述,[2]聚焦多传感器场景,[3]讨论噪声协方差自适应方法。需要特别注意相机AF系统的特殊需求——实时性要求高(每秒数十次对焦计算)、噪声环境复杂(机械振动/弱光干扰),这些在解释原理时要结合具体案例。 技术要点需要分层解析:先明确标准卡尔曼滤波的局限(固定噪声参数),再展开自适应机制。对于相机AF场景,重
recommend-type

EIA-CEA 861B标准深入解析:时间与EDID技术

EIA-CEA 861B标准是美国电子工业联盟(Electronic Industries Alliance, EIA)和消费电子协会(Consumer Electronics Association, CEA)联合制定的一个技术规范,该规范详细规定了视频显示设备和系统之间的通信协议,特别是关于视频显示设备的时间信息(timing)和扩展显示识别数据(Extended Display Identification Data,简称EDID)的结构与内容。 在视频显示技术领域,确保不同品牌、不同型号的显示设备之间能够正确交换信息是至关重要的,而这正是EIA-CEA 861B标准所解决的问题。它为制造商提供了一个统一的标准,以便设备能够互相识别和兼容。该标准对于确保设备能够正确配置分辨率、刷新率等参数至关重要。 ### 知识点详解 #### EIA-CEA 861B标准的历史和重要性 EIA-CEA 861B标准是随着数字视频接口(Digital Visual Interface,DVI)和后来的高带宽数字内容保护(High-bandwidth Digital Content Protection,HDCP)等技术的发展而出现的。该标准之所以重要,是因为它定义了电视、显示器和其他显示设备之间如何交互时间参数和显示能力信息。这有助于避免兼容性问题,并确保消费者能有较好的体验。 #### Timing信息 Timing信息指的是关于视频信号时序的信息,包括分辨率、水平频率、垂直频率、像素时钟频率等。这些参数决定了视频信号的同步性和刷新率。正确配置这些参数对于视频播放的稳定性和清晰度至关重要。EIA-CEA 861B标准规定了多种推荐的视频模式(如VESA标准模式)和特定的时序信息格式,使得设备制造商可以参照这些标准来设计产品。 #### EDID EDID是显示设备向计算机或其他视频源发送的数据结构,包含了关于显示设备能力的信息,如制造商、型号、支持的分辨率列表、支持的视频格式、屏幕尺寸等。这种信息交流机制允许视频源设备能够“了解”连接的显示设备,并自动设置最佳的输出分辨率和刷新率,实现即插即用(plug and play)功能。 EDID的结构包含了一系列的块(block),其中定义了包括基本显示参数、色彩特性、名称和序列号等在内的信息。该标准确保了这些信息能以一种标准的方式被传输和解释,从而简化了显示设置的过程。 #### EIA-CEA 861B标准的应用 EIA-CEA 861B标准不仅适用于DVI接口,还适用于HDMI(High-Definition Multimedia Interface)和DisplayPort等数字视频接口。这些接口技术都必须遵循EDID的通信协议,以保证设备间正确交换信息。由于标准的广泛采用,它已经成为现代视频信号传输和显示设备设计的基础。 #### EIA-CEA 861B标准的更新 随着技术的进步,EIA-CEA 861B标准也在不断地更新和修订。例如,随着4K分辨率和更高刷新率的显示技术的发展,该标准已经扩展以包括支持这些新技术的时序和EDID信息。任何显示设备制造商在设计新产品时,都必须考虑最新的EIA-CEA 861B标准,以确保兼容性。 #### 结论 EIA-CEA 861B标准是电子显示领域的一个重要规范,它详细定义了视频显示设备在通信时所使用的信号时序和设备信息的格式。该标准的存在,使得不同厂商生产的显示设备可以无缝连接和集成,极大地增强了用户体验。对于IT专业人士而言,了解和遵守EIA-CEA 861B标准是进行视频系统设计、故障诊断及设备兼容性测试的重要基础。
recommend-type

【DFLauncher应用实战】:如何将DFLauncher融入矮人要塞并提升效率

# 摘要 DFLauncher是一款功能全面的游戏管理工具,旨在简化游戏安装、启动和维护过程。本文介绍了DFLauncher的基本使用方法,详细解析了其核心功能,包括游戏库管理、游戏配置优化、更新机制等。同时,文章探讨了DFLauncher在特定游戏“矮人要塞”中的集成应用,以及通过插件和脚本进行的高级定制。故障诊断与系统优化章节提供了实用的诊断方法和性能提升技巧。最后,本文展望了DFLauncher的未来发展方向,并鼓励社区贡献和用户反馈,以满足不断变化的用户需求。 # 关键字 DFLauncher;游戏管理工具;安装配置;性能优化;故障诊断;社区贡献;定制化扩展;网络功能集成 参考资源
recommend-type

银河麒麟系统打开屏保

<think>嗯,用户的问题是关于银河麒麟操作系统如何开启屏幕保护程序。这个问题其实挺实用的,毕竟长时间盯着电脑屏幕容易造成视觉疲劳,屏幕保护能起到一定的保护作用。 从用户提供的引用内容来看,引用[2]提到了银河麒麟系统的常见问题处理,包括重启输入法和双屏配置问题,虽然不直接相关,但说明用户对系统设置有一定了解。引用[3]是关于安装cmake的,可能用户之前尝试过其他系统配置操作。 用户可能是在办公环境中使用银河麒麟系统,需要保护视力。考虑到银河麒麟是基于Linux开发的国产操作系统,它的屏幕保护设置应该和主流Linux发行版类似,但可能有自己的特色功能。 我回忆了一下Linux系统的屏
recommend-type

SQL Server 2000官方资料:数据转换与优化

根据提供的文件信息,可以推断出以下知识点: 1. SQL Server 2000官方资料:首先,我们应了解SQL Server 2000是微软发布的一款关系型数据库管理系统,属于SQL Server数据库产品系列的早期版本。官方资料将涵盖此版本的安装、配置、管理以及编程接口等方面的详尽信息。了解SQL Server 2000的官方文档是掌握该软件的基础,对于数据库管理员和开发者来说至关重要。 2. 数据转换:在SQL Server 2000中,数据转换通常涉及将数据从一个格式转换成另一个格式,以便进行进一步的处理或分析。这可能包括使用DTS (Data Transformation Services) 进行数据的导入导出,或是通过编写SQL语句及存储过程来实现复杂的数据清洗和转换逻辑。数据转换的知识点会包括DTS包的设计与执行、各种数据源的连接方法、以及转换过程中的错误处理和日志记录。 3. 数据优化:数据库性能优化是SQL Server 2000的核心知识点之一。数据优化旨在提升数据库的运行效率,包括查询优化、索引管理、存储过程优化等。查询优化可能涉及到使用SQL Server的查询分析器分析查询计划,进而调整SQL语句以提高执行效率。索引管理包括创建、维护和优化索引,而存储过程优化则关注于编写高效的存储过程以减少数据库资源的消耗。 4. 数据备份与恢复:在数据库管理中,数据备份与恢复是保证数据安全性和可靠性的重要措施。SQL Server 2000提供了多种备份选项,例如完整备份、差异备份和日志备份,以及还原数据库的不同策略。管理员需要掌握如何创建备份计划,执行备份操作,同时理解不同备份类型的特点以及在数据丢失或损坏时如何执行恰当的还原操作。 5. 标签信息:"2000官方资料 sqlserver":这个标签强调了文档或文件内容的专一性,指出它专门涉及SQL Server 2000版本。对于IT专业人员来说,理解特定版本的特点和操作是必要的,因为每个版本的数据库管理系统都可能有它独特的功能和限制。因此,此标签提示我们,文中所涉及的技巧、方法和工具都是针对SQL Server 2000的,可能与最新版本有所不同。 6. 压缩包子文件的文件名称列表:虽然提供的列表中只有一个具体的文件名和一个数字,但我们可以推断“中国IT认证实验室学习下载频道.txt”可能是一个包含学习材料下载链接、说明或指南的文本文件。这类文件一般用来提供学习资源信息,可能包含针对SQL Server 2000学习路径的建议,例如官方文档的下载链接、学习书籍的推荐、在线课程介绍等。数字“228”可能是某种编码或文件编号,没有更多的上下文信息,我们难以确定其具体含义。 总结来说,从文件信息中我们可以得知,主要知识点集中在SQL Server 2000的官方资料学习上,具体包括数据转换、数据优化、数据备份与恢复等多个方面。这些内容对于掌握SQL Server 2000的操作和管理至关重要。标签信息进一步指明了内容的专业性和版本特定性,而文件名称列表则可能指向一些学习资源的下载指引。对于数据库管理员和开发者而言,这些知识点的掌握是进行数据库设计、管理和故障排除的基础。