Path 接口使用指南
在嵌入式应用程序中,此页面上的 JavaScript 可以使用window.Path
对象执行代码并与后端交互。适用于任何嵌入式应用程序环境。初始化通信通道
在应用程序加载时,设置通信通道以便 JavaScript 可以与 Path 通信。 将qwebchannel.js
文件加载到你的应用程序中:你可以从指定位置获取<head> <script language="javascript" src="./qwebchannel.js"></script> </head>
qwebchannel.js
并将其部署到你的应用程序的 Web 服务器中。创建 Web 通道通信对象
在应用程序加载完成后,创建 Web 通道通信对象:window.onload = function() { if (!qt || !qt.webChannelTransport) { // 如果 Web 通道传输对象不存在,说明不在嵌入式应用程序中运行。 return; } new QWebChannel(qt.webChannelTransport, function(channel) { // 将 Path 桥接对象分配给全局 window 对象,使其在整个应用程序中可用。 window.Path = channel.objects.path; }); }
执行表达式获取信息
执行表达式,需要先启用对应的权限window.Path.Info
并获取执行后的状态。读取权限信息, 有以下类型
window.Path.Permissions.ReadUser
window.Path.Permissions.WriteUser
window.Path.Permissions.ExeUser
window.Path.Permissions.ReadGroup
window.Path.Permissions.WriteGroup
window.Path.Permissions.ExeGroup
window.Path.Permissions.ReadOther
window.Path.Permissions.WriteOther
window.Path.Permissions.ExeOther
window.Path.Permissions.ReadOwner
window.Path.Permissions.WriteOwner
window.Path.Permissions.ExeOwner
if (window.Path && window.Path.Info) { window.Path.permissions( "c:/windows", window.Path.Permissions.ReadUser function(result) { alert(result); } ); }
字符串表达式,获取文件修改时间
读取时间信息, 有以下类型
window.Path.TextDate
window.Path.ISODate
window.Path.ISODateWithMs
window.Path.RFC2822Date
if (window.Path && window.Path.Info) { window.Path.modified( "c:/windows", window.Path.ISODate, function(result) { alert(result); } ); }
字符串表达式,获取文件创建时间
if (window.Path && window.Path.Info) { window.Path.created( "c:/windows", window.Path.ISODate, function(result) { alert(result); } ); }
执行表达式读取
需要先启用对应的权限window.Path.Read
并提供一个回调函数。当代码执行完成时,桥接将调用该函数并返回结果。字符串表达式,获取目录里面的信息
if (window.Path && window.Path.Read) { window.Path.listDir( "c:/windows", function(result) { alert(result); } ); }
执行表达式删除
需要先启用对应的权限window.Path.Delete
并提供一个回调函数。当代码执行完成时,桥接将调用该函数并返回结果。字符串表达式,删除文件夹
if (window.Path && window.Path.Delete) { window.Path.rmdir( "c:/windows", function(result) { alert(result); } ); }
字符串表达式,删除文件
if (window.Path && window.Path.Delete) { window.Path.rmFile( "c:/windows", function(result) { alert(result); } ); }
执行表达式创建
需要先启用对应的权限window.Path.Write
并提供一个回调函数。当代码执行完成时,桥接将调用该函数并返回结果。字符串表达式,创建文件夹
if (window.Path && window.Path.Write) { window.Path.mkDir( "c:/test", function(result) { alert(result); } ); }
执行表达式修改
需要先启用对应的权限window.Path.Modify
并提供一个回调函数。当代码执行完成时,桥接将调用该函数并返回结果。字符串表达式,修改名称
if (window.Path && window.Path.Modify) { window.Path.rename( "c:/test", "c:/bbb", function(result) { alert(result); } ); }
执行表达式打开
需要先启用对应的权限window.Path.Execute
并提供一个回调函数,第二个参数是选中。当代码执行完成时,桥接将调用该函数并返回结果,在资源管理器中展开文件夹。字符串表达式
if (window.Path && window.Path.Execute) { window.Path.open( "c:/test", true, function(result) { alert(result); } ); }