一、先看完整的源码

#ifdef Q_OS_WIN
#include <Windows.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "shell32.lib")
#endifvoid DistortionCalibWidget::slotToolButtonMspaint()
{//C:\Windows\SysWOW64\mspaint.exe//C:\Windows\System32\mspaint.exestd::string strImage = m_strPathNameImageOrg.toStdString();qDebug() << m_strPathNameImageOrg;//将'/'转'\\',斜杠转反斜杠QString strNat = QDir::toNativeSeparators(m_strPathNameImageOrg);std::string strImageNew = strNat.toStdString();qDebug() << strNat;//已知文件路径全名,求文件所在文件夹的路径std::string directory;const size_t last_slash_idx1 = strImageNew.rfind('\\');const size_t last_slash_idx2 = strImageNew.rfind('/');if (std::string::npos != last_slash_idx1){directory = strImageNew.substr(0, last_slash_idx1);}if (std::string::npos != last_slash_idx2){directory = strImageNew.substr(0, last_slash_idx2);}directory = ("\"") + directory + ("\""); //加引号是为了避免路径有空格,因为cmd命令不认空格std::cout << directory << std::endl;std::string strEnd = ("\"") + strImageNew + ("\""); //加引号是为了避免路径有空格,因为cmd命令不认空格//打开方式1::ShellExecuteA(NULL, "open", "mspaint.exe", strEnd.c_str(), NULL, SW_SHOWMAXIMIZED); //只认'\\'路径//打开方式2//::ShellExecuteA(NULL, "open", "mspaint.exe", strEnd.c_str(), directory.c_str(), SW_SHOWMAXIMIZED);
}

二、注意事项:

1、ShellExecuteA是Windows的函数,只认'\\'的路径方式,不认'/'的方式。

2、Qt得到的路径默认是'/'的方式。

3、所以需要转换路径(/斜杠与\反斜杠转换)

//获取应用程序的目录
QString strCurrentApplicationDirPath=QCoreApplication::applicationDirPath();
qDebug()<<strCurrentApplicationDirPath;/*将/转\(斜杠转反斜杠)*/
QString strPath=QDir::toNativeSeparators(strCurrentApplicationDirPath);
qDebug()<<strPath;/*将\转/(反斜杠转斜杠)*/
QString strPath2=QDir::fromNativeSeparators(strPath);
qDebug()<<strPath2;

输出:

"D:/QT5SourceCode/build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/debug"
"D:\\QT5SourceCode\\build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug\\debug"
"D:/QT5SourceCode/build-untitled-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/debug"

---

std::string srcPath;

std::string dstPath(srcPath);

dstPath.insert(dstPath.size() - 4, "2dst");

Qt/C++调用Windows画图板mspaint,打开指定路径的图片文件,从文件路径中提取目录名和文件名相关推荐

  1. 怎样用调用资源管理器explore.exe打开指定的文件夹

    怎样用调用资源管理器explore.exe打开指定的文件夹 VCL组件开发及应用 http://www.delphi2007.net/DelphiVCL/html/delphi_20061225173 ...

  2. Mac技巧之苹果电脑Mac OS X系统上,类似Windows画图板的软件paintbrush介绍与下载

    from:http://www.mac52ipod.cn/post/paintbrush-Mac-OS-X-Windows-HuaTu.php PC用户可能经常用Windows自带的画图板做简单的图片 ...

  3. 仿制Windows画图板程序

    仿制Windows画图板程序 控件 代码 效果图 控件 新建一个Windows窗体应用程序,将窗体Form1调整到适当大小,在窗体Form1中分别添加1个Panel.1个PictureBox和1个St ...

  4. android saf 打开指定目录,并操作相关文件

    android saf 打开指定目录,并操作相关文件 saf存储访问框架(android 4.4 引入)全称 Storage Access Framework 用户可轻松在其所有首选文档存储提供程序中 ...

  5. Python调Windows的资源管理器打开指定目录

    2019独角兽企业重金招聘Python工程师标准>>> 使用Python在Windows自定义命令时候遇到一个问题,调用Windows文件选择器打开指定文件目录. 这里介绍两种方式: ...

  6. 基于MATLAB的仿windows画图板功能的实现

    1.仿真预览 2.部分核心代码 % --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObje ...

  7. windows画图板 ESL转RGB 实现区间渐变色

    2021.6.21记载 根据数值确定渐变范围[-1,1] 主要实现红色向绿色的渐变效果 色调(E)调低偏向红色,调高偏向绿色[0-80] 饱和度(S)越高颜色越深,越低颜色越浅[0-240] 亮度(L ...

  8. Windows 10免费原生打开HEIC格式的图片(无需转换,直接用照片打开)

    安装HEIF扩展 在微软应用商店搜索HEIF,第一个就是这个扩展. 安装HEVC解码器 在微软应用商店搜索HEVC,第一个结果就是HEVC视频扩展,但是这个要付费,后面有免费的办法. 这个里面才是图片 ...

  9. Windows利用bat程序打开指定网址

    很简单,只需start空格加网址. start 网址 还可以指定使用哪一个浏览器而非默认浏览器. 比如说我要用IE浏览器打开B站,那么代码如下-- start iexplore.exe https:/ ...

最新文章

  1. 如何用命令将本地项目上传到git
  2. 前端利器—1—转型JS编程
  3. leetcode算法题--煎饼排序
  4. Eclipse Add generated serial version ID报错解决方案
  5. python db2查询_如何将DB2查询转换为python脚本
  6. WCF系列(一)BasicHttpBinding 和 WsHttpBinding 的不同点
  7. 数据分析师免费课程网址
  8. java项目分页_Java项目实战分页类
  9. 谁说大学生找工作难?鄙视说这样话的人!!
  10. 2017 开源软件排行_2017年最佳开源教程
  11. html数字增加动态效果,jQuery实现数字自动增加或者减少的动画效果示例_泠吢_前端开发者...
  12. SQLi LABS Less-5 报错注入+布尔盲注
  13. 2015中国银联业务(武汉)面试经验(软件开发)
  14. Mybatis 缓存配置 ,如何禁用缓存与一些细节
  15. 003-Java技术体系
  16. linux分区修复命令行,Linux技巧:使用Fsck命令修复损坏的分区
  17. RPL协议的原理与安全机制
  18. 520,让爱的传递永不停歇
  19. leetcode每日一题第三十二天-剑指 Offer 65. 不用加减乘除做加法(easy??middle了吧)
  20. Linux C++ 乱码字符转换问题 GBK转UTF8

热门文章

  1. Leetcode 评论区代码(MarkDown)
  2. 51单片机(一)工程建立、点亮任意几个LED灯、烧录、锁存器
  3. java 报文怎么构造的,详解http报文,mt900报文
  4. android 19版本下载,想看app最新版
  5. Qt实现长图片的放大缩小以及动态显示
  6. Ubuntu18.04 ROS-Melodic安装Moveit
  7. 在jetson nano上安装ROS melodic
  8. python set转为list_python 怎么把set转成list
  9. eclipse提示框全黑色背景怎么改
  10. KPlayer for Mac(影音全能播放器工具)