當前位置:首頁 » 文件管理 » 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 瀏覽:357
奪寶網站源碼 發布:2024-10-25 00:19:02 瀏覽:454
編程文本編輯器 發布:2024-10-25 00:09:28 瀏覽:970
編程徐帥 發布:2024-10-25 00:03:25 瀏覽:304
手機安卓模擬器如何打開文件 發布:2024-10-25 00:02:55 瀏覽:720
pythonday 發布:2024-10-24 23:55:47 瀏覽:425
g編譯c文件 發布:2024-10-24 23:55:03 瀏覽:292
電信上傳速度限制破解 發布:2024-10-24 23:44:17 瀏覽:453
戰地五為什麼連接不了伺服器 發布:2024-10-24 23:37:36 瀏覽:482
安卓如何下載國外網站 發布:2024-10-24 23:30:35 瀏覽:135