导航:首页 > 文件处理 > qt中打开选择文件夹

qt中打开选择文件夹

发布时间:2023-08-31 22:04:06

Ⅰ 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怎么打开指定文件夹下的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
}

Ⅳ 在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里面用treeview显示的目录和文件选中后怎么打开

感觉应该可以获得选中文件的目录,然后用系统调用打开

阅读全文

与qt中打开选择文件夹相关的资料

热点内容
网通的宽带玩电信服务器地址 浏览:828
解压视频搞笑大全爆笑 浏览:614
米兔解压积木隐藏款金属 浏览:574
window命令行svn 浏览:616
8051单片机包含多大的ram 浏览:812
man文件linux 浏览:283
javaweb实现页面跳转 浏览:126
命令如什么 浏览:316
centos如何使用ftp服务器 浏览:982
直立车陀螺仪算法 浏览:70
coreldrawpdf下载 浏览:896
虚拟主机云服务器软件服务 浏览:372
苹果的怎么拉安卓的打游戏 浏览:414
游戏程序员负责角色 浏览:315
于丹pdf 浏览:718
反编译ref 浏览:551
鸿蒙智能文件夹怎么弄 浏览:548
grunt压缩html 浏览:792
macpdfword转换器 浏览:909
压缩面膜是什么材质 浏览:356