簡要說明:我的Qt工具,我想,一旦用戶下面的東西擊中了關閉按鈕發生如何使用完整路徑檢索文件名數據寫入它
1)文件對話框,框中將顯示保存/取消選項,並在其中包含 默認文件名。 2)如果用戶已將該文件保存在其計算機上的不同位置,我應該能夠在該保存的文件上寫入日誌。
我已經完成了第一部分,但我對如何在用戶已關閉對話框時檢索具有完整路徑的文件名無能爲力。
第1部分的MY代碼如下所示。
void some_class ::on_write_file()
{
// some code ..
bla bla bla
switch(set_file_name_for_logging(QString::fromStdString(filename) , this))
{
case QDialog::Accepted :
std::cout <<" Retrive filename and full path name from the location where user has saved the file " and write on it;
break;
case QDialog::Rejected :
break;
default :
throw_error("Unexpected return value from save_ dump file dialog");
break;
}
}
}
int set_file_name_for_logging(const QString& str, som_class *cal)
{
QFileDialog file_dialog(cal);
file_dialog.setDirectory(".");
file_dialog.setAcceptMode(QFileDialog::AcceptSave);
file_dialog.setNameFilter( ("Text files (*.txt)"));
file_dialog.selectFile(str);
int ret = file_dialog.exec();
return ret ;
}
http://qt-project.org/doc/qt-5.1/qtwidgets/qfiledialog.html#selectedFiles? – lpapp
感謝大家的快速回復..我已經解決了問題 – samprat
好的,希望我們有用。 :) – lpapp