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。

问题解决。

相关推荐
caimouse1 天前
Reactos 第 7 章 视窗报文 — 7.5 视窗报文的发送
windows
金色熊族1 天前
QTransform使用心得(二)--仿射变换、非仿射变换、矩阵
qt·线性代数·矩阵
callJJ1 天前
Volta + Claude Code 在 Windows 上的路径 Bug 复盘
windows·bug
女神下凡1 天前
这是 Cursor(Composer) 的五种核心交互模式
服务器·人工智能·windows·vscode·microsoft
techdashen1 天前
从 Windows 的 ping.exe 入手:动态库、调用约定与 Rust FFI
开发语言·windows·rust
独隅1 天前
IntelliJ IDEA 在 Windows 上的完整安装与使用指南
java·windows·intellij-idea
逻极1 天前
Windows 平台 Ollama AMD GPU 一键编译指南:基于 ROCm 7.1 的自动化实战
人工智能·windows·stm32·自动化·gpu·amd·ollama
乌托邦2号1 天前
Qt实现CS的自动化构建流程
qt·自动化
caimouse1 天前
Reactos 第 9 章 设备驱动 — 9.13 同步I/O与异步I/O
windows
caimouse1 天前
Reactos 第 9 章 设备驱动 — 9.10 磁盘的Miniport驱动模块
windows·嵌入式硬件