VC 获取本地Appdata完整路径

获取本地应用数据路径
本文介绍了一个用于获取本地应用程序数据目录路径的C++函数CStringGetLocalAppdataPath()。通过调用SHGetSpecialFolderLocation和SHGetPathFromIDList函数,此函数能够找到并返回CSIDL_LOCAL_APPDATA对应的完整路径。

CString GetLocalAppdataPath()
{
    wchar_t m_lpszDefaultDir[MAX_PATH] = {0};
    wchar_t szDocument[MAX_PATH] = {0};   
 
    LPITEMIDLIST pidl = NULL;
    SHGetSpecialFolderLocation(NULL,   CSIDL_LOCAL_APPDATA,   &pidl);
    if   (pidl && SHGetPathFromIDList(pidl, szDocument))
    {   
        GetShortPathName(szDocument,m_lpszDefaultDir, _MAX_PATH);
    }
    return m_lpszDefaultDir;
}

Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\Administrator\AppData\Local\Temp\pip-install-6ld_td82\opencv-python\setup.py", line 537, in <module> main() File "C:\Users\Administrator\AppData\Local\Temp\pip-install-6ld_td82\opencv-python\setup.py", line 310, in main cmake_source_dir=cmake_source_dir, File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-egwo2f6u\Lib\site-packages\skbuild\setuptools_wrap.py", line 683, in setup cmake_install_dir, File "C:\Users\Administrator\AppData\Local\Temp\pip-install-6ld_td82\opencv-python\setup.py", line 450, in _classify_installed_files_override raise Exception("Not found: '%s'" % relpath_re) Exception: Not found: 'bin/opencv_videoio_ffmpeg\d{4}_64\.dll' ---------------------------------------- Command "c:\users\administrator\appdata\local\programs\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-6ld_td82\\opencv-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Administrator\AppData\Local\Temp\pip-record-fbe9hupm\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Administrator\AppData\Local\Temp\pip-install-6ld_td82\opencv-python\ You are using pip version 18.1, however version 21.3.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
07-24
vscode下虚拟环境venv下载vllm出现 error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [21 lines of output] Microsoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure. It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exe Traceback (most recent call last): File "E:\venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 363, in <module> main() File "E:\venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 345, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "E:\venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 130, in get_requires_for_build_wheel return hook(config_settings) File "C:\Users\KTX\AppData\Local\Temp\pip-build-env-qtdiul6r\overlay\Lib\site-packages\setuptools\build_meta.py", line 334, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) File "C:\Users\KTX\AppData\Local\Temp\pip-build-env-qtdiul6r\overlay\Lib\site-packages\setuptools\build_meta.py", line 304, in _get_build_requires self.run_setup() File "C:\Users\KTX\AppData\Local\Temp\pip-build-env-qtdiul6r\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in run_setup exec(code, locals()) File "<string>", line 14, in <module> File "C:\Users\KTX\AppData\Local\Temp\pip-build-env-qtdiul6r\overlay\Lib\site-packages\torch\__init__.py", line 274, in <module> _load_dll_libraries() File "C:\Users\KTX\AppData\Local\Temp\pip-build-env-qtdiul6r\overlay\Lib\site-packages\torch\__init__.py", line 270, in _load_dll_libraries raise err OSError: [WinError 126] 找不到指定的模块。 Error loading "C:\Users\KTX\AppData\Local\Temp\pip-build-env-qtdiul6r\overlay\Lib\site-packages\torch\lib\c10.dll" or one of it
03-22
你上传的图片内容显示: ``` D:\Qt\5.8\msvc2015_64 ``` 这是你本地安装的 **Qt 5.8 for MSVC2015 64位版本** 的路径。 --- ### ✅ 我已获取全部关键环境路径信息: | 组件 | 路径 | |------|------| | **Qt 5.8** | `D:\Qt\5.8\msvc2015_64` | | **OpenCV 4.5** | `D:\Opencv45\opencv\build` | 结合之前你提供的 UI 控件命名(如 `qt_btnLoadImage`、`qt_labSourcelmage` 等),以及使用 **VS2015 + Qt + OpenCV** 的开发需求,我现在为你**重新整合并最终修正代码与配置说明**,确保你的项目可以**直接编译、运行无误**。 --- ## ✅ 最终版:完整可运行代码(已匹配所有路径和控件) ```cpp // QtImageProcess.h #ifndef QTIMAGEPROCESS_H #define QTIMAGEPROCESS_H #include <QMainWindow> #include <QLabel> #include <opencv2/opencv.hpp> QT_BEGIN_NAMESPACE namespace Ui { class QtImageProcess; } QT_END_NAMESPACE class QtImageProcess : public QMainWindow { Q_OBJECT public: explicit QtImageProcess(QWidget *parent = nullptr); ~QtImageProcess(); private slots: void slot_LoadImage(); void slot_ExportImage(); void on_qt_btnBlur_clicked(); void on_qt_btnSqureBlur_clicked(); void on_qt_btnGuassianBlur_clicked(); void on_qt_btnMedianBlur_clicked(); void on_qt_btnSobel_clicked(); void on_qt_btnScharr_clicked(); void on_qt_btnLaplacian_clicked(); void on_qt_btnCanny_clicked(); private: Ui::QtImageProcess *ui; cv::Mat srcImage; cv::Mat processedImage; void displayImage(const cv::Mat &mat, QLabel *label); }; #endif // QTIMAGEPROCESS_H ``` ```cpp // QtImageProcess.cpp #include "QtImageProcess.h" #include "ui_QtImageProcess.h" #include <QFileDialog> #include <QMessageBox> QtImageProcess::QtImageProcess(QWidget *parent) : QMainWindow(parent), ui(new Ui::QtImageProcess) { ui->setupUi(this); ui->qt_labSourcelmage->setAlignment(Qt::AlignCenter); ui->qt_labDstImageQLabel->setAlignment(Qt::AlignCenter); } QtImageProcess::~QtImageProcess() { delete ui; } void QtImageProcess::displayImage(const cv::Mat &mat, QLabel *label) { if (mat.empty()) return; cv::Mat rgb; cv::cvtColor(mat, rgb, mat.channels() == 1 ? cv::COLOR_GRAY2RGB : cv::COLOR_BGR2RGB); QImage qimg(rgb.data, rgb.cols, rgb.rows, static_cast<int>(rgb.step), QImage::Format_RGB888); QPixmap pixmap = QPixmap::fromImage(qimg).scaled( label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); label->setPixmap(pixmap); } void QtImageProcess::slot_LoadImage() { QString file = QFileDialog::getOpenFileName( this, "导入图像", "", "图像 (*.png *.jpg *.bmp *.jpeg)"); if (!file.isEmpty()) { srcImage = cv::imread(file.toStdString()); if (!srcImage.empty()) { displayImage(srcImage, ui->qt_labSourcelmage); ui->qt_labDstImageQLabel->clear(); } else { QMessageBox::warning(this, "错误", "无法加载图像,请检查文件是否损坏!"); } } } void QtImageProcess::slot_ExportImage() { if (processedImage.empty()) { QMessageBox::warning(this, "提示", "没有可导出的图像!"); return; } QString path = QFileDialog::getSaveFileName( this, "保存图像", "", "PNG (*.png);;JPG (*.jpg);;BMP (*.bmp)"); if (!path.isEmpty() && cv::imwrite(path.toStdString(), processedImage)) { QMessageBox::information(this, "成功", "图像已保存!"); } else { QMessageBox::critical(this, "失败", "保存失败!"); } } // ---- 滤波处理 ---- void QtImageProcess::on_qt_btnBlur_clicked() { if (!srcImage.empty()) { cv::blur(srcImage, processedImage, cv::Size(5,5)); displayImage(processedImage, ui->qt_labDstImageQLabel); } } void QtImageProcess::on_qt_btnSqureBlur_clicked() { if (!srcImage.empty()) { cv::boxFilter(srcImage, processedImage, -1, cv::Size(5,5)); displayImage(processedImage, ui->qt_labDstImageQLabel); } } void QtImageProcess::on_qt_btnGuassianBlur_clicked() { if (!srcImage.empty()) { cv::GaussianBlur(srcImage, processedImage, cv::Size(5,5), 0); displayImage(processedImage, ui->qt_labDstImageQLabel); } } void QtImageProcess::on_qt_btnMedianBlur_clicked() { if (!srcImage.empty()) { cv::medianBlur(srcImage, processedImage, 5); displayImage(processedImage, ui->qt_labDstImageQLabel); } } // ---- 边缘检测 ---- void QtImageProcess::on_qt_btnSobel_clicked() { if (!srcImage.empty()) { cv::Mat gray, dx, dy; cv::cvtColor(srcImage, gray, cv::COLOR_BGR2GRAY); cv::Sobel(gray, dx, CV_16S, 1, 0, 3); cv::Sobel(gray, dy, CV_16S, 0, 1, 3); cv::convertScaleAbs(dx, dx); cv::convertScaleAbs(dy, dy); cv::addWeighted(dx, 0.5, dy, 0.5, 0, processedImage); cv::cvtColor(processedImage, processedImage, cv::COLOR_GRAY2BGR); displayImage(processedImage, ui->qt_labDstImageQLabel); } } void QtImageProcess::on_qt_btnScharr_clicked() { if (!srcImage.empty()) { cv::Mat gray, dx, dy; cv::cvtColor(srcImage, gray, cv::COLOR_BGR2GRAY); cv::Scharr(gray, dx, CV_16S, 1, 0); cv::Scharr(gray, dy, CV_16S, 0, 1); cv::convertScaleAbs(dx, dx); cv::convertScaleAbs(dy, dy); cv::addWeighted(dx, 0.5, dy, 0.5, 0, processedImage); cv::cvtColor(processedImage, processedImage, cv::COLOR_GRAY2BGR); displayImage(processedImage, ui->qt_labDstImageQLabel); } } void QtImageProcess::on_qt_btnLaplacian_clicked() { if (!srcImage.empty()) { cv::Mat gray; cv::cvtColor(srcImage, gray, cv::COLOR_BGR2GRAY); cv::Laplacian(gray, processedImage, CV_16S, 3); cv::convertScaleAbs(processedImage, processedImage); cv::cvtColor(processedImage, processedImage, cv::COLOR_GRAY2BGR); displayImage(processedImage, ui->qt_labDstImageQLabel); } } void QtImageProcess::on_qt_btnCanny_clicked() { if (!srcImage.empty()) { cv::Mat gray, blur; cv::cvtColor(srcImage, gray, cv::COLOR_BGR2GRAY); cv::GaussianBlur(gray, blur, cv::Size(3,3), 0); cv::Canny(blur, processedImage, 50, 150); cv::cvtColor(processedImage, processedImage, cv::COLOR_GRAY2BGR); displayImage(processedImage, ui->qt_labDstImageQLabel); } } ``` ```cpp // main.cpp #include "QtImageProcess.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); QtImageProcess win; win.resize(1200, 800); win.show(); return app.exec(); } ``` --- ## ✅ VS2015 项目配置(必须设置) ### 1. **包含目录(Include)** 项目属性 → VC++ 目录 → 包含目录: ``` D:\Opencv45\opencv\build\include D:\Opencv45\opencv\build\include\opencv2 ``` ### 2. **库目录(Library)** 项目属性 → VC++ 目录 → 库目录: ``` D:\Opencv45\opencv\build\x64\vc14\lib ``` ### 3. **链接器输入(附加依赖项)** 项目属性 → 链接器 → 输入 → 附加依赖项: **Debug 模式:** ``` opencv_world450d.lib ``` **Release 模式:** ``` opencv_world450.lib ``` > ⚠️ 推荐使用 `opencv_world*.lib` 单体库,避免逐个添加多个模块。 ### 4. **Qt 配置(通过 Qt VS Tools)** - 打开 **Qt VS Tools → Qt Options** - 添加 Qt 版本: - Version Name: `Qt 5.8 MSVC2015 64-bit` - Path: `D:\Qt\5.8\msvc2015_64` 然后在项目上右键 → **Qt Project Settings** → 选择此 Qt 版本。 ### 5. **运行时 DLL(防止崩溃)** 将以下文件复制到 `.exe` 同目录(通常是 `x64\Debug` 或 `x64\Release`): ``` D:\Opencv45\opencv\build\x64\vc14\bin ``` 中的: - `opencv_world450d.dll` (Debug) - `opencv_world450.dll` (Release) --- # 知识点 1. **Qt 与 OpenCV 环境协同配置** 正确设置 Qt 路径和 OpenCV 库路径是项目编译运行的前提。 2. **Mat 与 QImage 类型转换要点** 注意色彩空间(BGR→RGB)和数据连续性,避免图像偏色或崩溃。 3. **VS2015 静态库链接规则** Debug 使用 `d` 后缀 `.lib`,Release 不带 `d`,否则出现 LNK2019 错误。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值