Windows下对于Qt中带 / 的路径的处理

在Windows下,如果你想使用操作系统的分隔符显示用户的路径,请使用 toNativeSeparators()。

请看以下代码:

cpp 复制代码
void Player::on_playBtn_clicked() {
	if (this->m_url.isEmpty()) {
		openMedia();
		if (this->m_url.isEmpty())return;
	}
	qDebug()<< m_url.toUtf8();
	if (!vlc_player) {
		auto media = libvlc_media_new_path(this->vlc_ins, 
			m_url.toUtf8());
		if (!media) {
			qWarning("media new failed: % s", libvlc_errmsg());
			return;
		}
		this->vlc_player = libvlc_media_player_new_from_media(media);
		if (!vlc_player) {
			qWarning("vlc_player new failed: % s", libvlc_errmsg());
			return;
		}
		libvlc_media_release(media);
	}
	libvlc_media_player_set_hwnd(vlc_player, (void*)ui->videoWidget->winId());
	libvlc_media_player_play(this->vlc_player);
}

打印输出:

"E:/Res/VideoRes/output.mp4"
media new failed: Unknown error

这个问题在于路径方面存在 / ,要解决这个问题就要使用QDir里面的一个静态成员函数:toNativeSeparators。

问题解决。

相关推荐
Abigail_chow1 小时前
EXCEL如何快速批量给两字姓名中间加空格
windows·microsoft·excel·学习方法·政务
love530love3 小时前
【笔记】在 MSYS2(MINGW64)中正确安装 Rust
运维·开发语言·人工智能·windows·笔记·python·rust
代码搬运媛4 小时前
“packageManager“: “[email protected]“ 配置如何正确启动项目?
windows·webpack
小道士写程序5 小时前
Qt 5.12 上读取 .xlsx 文件(Windows 平台)
开发语言·windows·qt
yxc_inspire10 小时前
基于Qt的app开发第十三天
c++·qt·app·tcp·面向对象
异常君10 小时前
Windows 与 Linux 虚拟内存机制对比:设计理念与实现差异
java·linux·windows
潇-xiao10 小时前
Qt 按钮类控件(Push Button 与 Radio Button)(1)
c++·qt
搏博12 小时前
将图形可视化工具的 Python 脚本打包为 Windows 应用程序
开发语言·windows·python·matplotlib·数据可视化
追风赶月、12 小时前
【QT】认识QT
开发语言·qt
电手13 小时前
Win10停更,Win11不好用?现在Mac电脑比Win11电脑更便宜
windows·macos·电脑·mac