当前位置:首页 » 文件管理 » qt打开文件夹

qt打开文件夹

发布时间: 2022-02-12 06:39:42

① 在mac下用QT编写代码想打开一个文件路径怎么设置

#include <QDesktopServices>

#include <QUrl>

QString runPath = QCoreApplication::applicationDirPath(); //获取exe路劲

QString Name = “student.rtf"”;
QString AllPath = QString("%1/%2").arg(runPath).arg(Name);

QFile bfilePath(AllPath);

if(!bfilePath.exists()){//是否存在

return;

}

QString filePath = "file:///" + AllPath; //打开文件夹用filse:///,打开网页用http://

QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));

② qt文件怎么打开

你说的是视频的格式吗?
用qq影音就可以打开

③ Qt怎么打开指定文件夹下的SQLite数据文件

首先,你的数据库肯定是跟着你的程序跑的,你不能指定你程序一定要用户放到D盘下面,也许用户喜欢把程序放到E盘下面呢。所以你在指定的时候最好用相对路径,假设你程序运行目录是在bin下面,你可以在bin下面创建一个data目录专门用来保存数据库,你指定目录的时候就可以
db.setDatabaseName("./data/student.db");//这样指定。

④ Qt 如何在打开的文件夹中鼠标选中某文件

是在打开的文件夹中自动选中某文件吧?不需要用鼠标。

试试看这一段:


boolOpenFolderAndSelectFile(constchar*filePath)
{
#ifdefQ_OS_WIN

LPITEMIDLISTpidl;
LPCITEMIDLISTcpidl;
LPSHELLFOLDERpDesktopFolder;
ULONGchEaten;
HRESULThr;
WCHARwfilePath[MAX_PATH+1]={0};

::CoInitialize(NULL);

if(SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
{
//IShellFolder::ParseDisplayName要传入宽字节
LPWSTRlpWStr=NULL;
//#ifdef_UNICODE
//_tcscpy(wfilePath,strFilePath);
//lpWStr=wfilePath;
//#else
MultiByteToWideChar(CP_ACP,0,(LPCSTR)filePath,-1,wfilePath,MAX_PATH);
lpWStr=wfilePath;
//#endif

hr=pDesktopFolder->ParseDisplayName(NULL,0,lpWStr,&chEaten,&pidl,NULL);
if(FAILED(hr))
{
pDesktopFolder->Release();
::CoUninitialize();
returnFALSE;
}

cpidl=pidl;

//SHOpenFolderAndSelectItems是非公开的API函数,需要从shell32.dll获取
//该函数只有XP及以上的系统才支持,Win2000和98是不支持的,考虑到Win2000
//和98已经基本不用了,所以就不考虑了,如果后面要支持上述老的系统,则要
//添加额外的处理代码
HMODULEhShell32DLL=::LoadLibraryA("shell32.dll");
//ASSERT(hShell32DLL!=NULL);
if(hShell32DLL!=NULL)
{
typedefHRESULT(WINAPI*pSelFun)(LPCITEMIDLISTpidlFolder,UINTcidl,LPCITEMIDLIST*apidl,DWORDdwFlags);
pSelFunpFun=(pSelFun)::GetProcAddress(hShell32DLL,"SHOpenFolderAndSelectItems");
//ASSERT(pFun!=NULL);
if(pFun!=NULL)
{
hr=pFun(cpidl,0,NULL,0);//第二个参数cidl置为0,表示是选中文件
if(FAILED(hr))
{
::FreeLibrary(hShell32DLL);
pDesktopFolder->Release();
::CoUninitialize();
returnFALSE;
}
}

::FreeLibrary(hShell32DLL);
}
else
{
pDesktopFolder->Release();
::CoUninitialize();
returnFALSE;
}

//释放pDesktopFolder
pDesktopFolder->Release();
}
else
{
::CoUninitialize();
returnFALSE;
}

::CoUninitialize();
returnTRUE;

#else
QStringpathIn(filePath);
QStringListscriptArgs;
scriptArgs<<QLatin1String("-e")<<QString::fromLatin1("tellapplication"Finder"torevealPOSIXfile"%1"").arg(pathIn.replace('\','/'));
QProcess::execute(QLatin1String("/usr/bin/osascript"),scriptArgs);
scriptArgs.clear();
scriptArgs<<QLatin1String("-e")<<QLatin1String("tellapplication"Finder"toactivate");
QProcess::execute("/usr/bin/osascript",scriptArgs);
returntrue;
#endif
}

⑤ qt如何实现点击按钮打开指定文档

connect(m_HelpAct, SIGNAL(triggered()), this, SLOT(OnHelp()));

实现槽函数:
void CXXX::OnHelp(){
QString runPath = QCoreApplication::applicationDirPath(); //获取exe路劲。

QString helpName = "帮助文档.pdf";

QString helpPath = QString("%1/%2").arg(runPath).arg(helpName);

QFile bfilePath(helpPath);

if(!bfilePath.exists()){

return;

}

QString filePath = "file:///" + helpPath; //打开文件夹用filse:///,打开网页用http://

QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));

⑥ qt 打开文件的几种方式

在/usr 目录下有configurefile1.xml 文件,在程序的执行文件所在目录下有个test文件夹,test里有configurefile2.xml ;configurefile3.xml 一:工程里使用后缀为qrc的资源文件: 比如 资源文件里的内容为:<RCC<qresource <file alias="configfile1"/usr/configurefile1.xml</file <file alias="configfile2"test/configurefile2.xml</file <filetest/configurefile3.xml</file </qresource</RCC(其中test是在工程执行文件所在路径下的一个文件夹) 这样在程序中: QFile file1(":/configfile1"); QFile file2(":/configfile2"); QFile file3(":/test/configurefile3.xml"); file1.open(QFile::ReadOnly); file2.open(QFile::ReadOnly); file3.open(QFile::ReadOnly);上述三条打开文件的操作都可以成功打开对应文件, 但是如果在资源文件里 如果对某个文件的引用里加了alias别名的操作,比如QFile file2(":/test/configurefile2.xml"); file2.open(QFile::ReadOnly);将打开文件失败。 QT里:/表示对资源的引用,不是表示当前目录 二 使用相对路径 QFile file3("test/configurefile3.xml"); file3.open(QFile::ReadOnly);OPEN成功 三 使用绝对路径

⑦ Qt中如何打开一个文件所在目录

用QDesktopServieres

QDesktopServices::openUrl(QUrl(youFilePath,QUrl::TolerantMode));

⑧ QT 如何读取共享磁盘的文件

先用“net use”命令建立到资源的连接,这个命令支持输入用户名密码,用来取代在资源管理器中输入用户名密码。然后QFile就可以访问了。

⑨ 关于QT中文件夹显示的问题

http://doc.trolltech.com/4.5/qicon.html

⑩ qt文件打开

这样吧,你把工程给我传过来 ,我在我的电脑上实验一下~

热点内容
劳拉与马ftp 发布:2024-10-25 00:21:16 浏览:359
夺宝网站源码 发布:2024-10-25 00:19:02 浏览:454
编程文本编辑器 发布:2024-10-25 00:09:28 浏览:972
编程徐帅 发布:2024-10-25 00:03:25 浏览:306
手机安卓模拟器如何打开文件 发布:2024-10-25 00:02:55 浏览:721
pythonday 发布:2024-10-24 23:55:47 浏览:425
g编译c文件 发布:2024-10-24 23:55:03 浏览:294
电信上传速度限制破解 发布:2024-10-24 23:44:17 浏览:453
战地五为什么连接不了服务器 发布:2024-10-24 23:37:36 浏览:485
安卓如何下载国外网站 发布:2024-10-24 23:30:35 浏览:136