[英]How to implement back and next button in custom file browse dialog Qt C++
我正在添加基於Qt的自定義文件打開對話框,因為本機QFileDialog導致對我的應用程序的某些阻塞。 我能夠執行以下操作。
但是找不到怎么辦
那么,如何在帶有C ++的Qt5中做到這一點?
我固定為
struct BrowsingHistory
{
QString dir;
BrowsingHistory * next;
BrowsingHistory * prev;
BrowsingHistory(const QString & path = "") :
dir(path),
next(0),
prev(0)
{}
};
BrowsingHistory *m_history;
BrowsingHistory *m_historyHead;
在構造函數中,我初始化為..
m_history = m_historyHead = new BrowsingHistory(/*Your default location*/);
m_historyHead用於析構函數中的內存釋放,因為它始終指向列表的開頭(基本上,結構BrowsingHistory是LinkedList的實現)
while(m_historyHead)
{
BrowsingHistory * temp = m_historyHead;
m_historyHead = m_historyHead->next;
delete temp;
}
m_history:始終指向當前路徑。
在單擊desktopButton,homeButton,parentButton時,我調用了RegisterHistory(),它定義為...
void RegisterHistory(const QString& dirPath)
{
if(m_history->dir != dirPath)
{
if(m_history->next)
{
m_history->next->dir = dirPath;
m_history = m_history->next;
BrowsingHistory * currentHistory = m_history->next;
while(currentHistory)
{
BrowsingHistory * temp = currentHistory;
currentHistory = currentHistory->next;
delete temp;
}
m_history->next = 0;
}
else
{
BrowsingHistory * currentHistory = new BrowsingHistory(dirPath);
currentHistory->prev = m_history;
m_history->next = currentHistory;
m_history = m_history->next;
}
}
}
現在是下一個和上一個插槽:
void btnNext_Clicked()
{
if(m_history && m_history->next)
{
QString dirPath = m_history->next->dir;
ui->listFileView->setRootIndex(m_pDirModel->setRootPath(dirPath));
m_history = m_history->next;
}
}
void btnBack_Clicked()
{
if(m_history && m_history->prev)
{
QString dirPath = m_history->prev->dir;
ui->listFileView->setRootIndex(m_pDirModel->setRootPath(dirPath));
m_history = m_history->prev;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.