step 1 :獲取路徑:
單擊按鍵【FilePath】,選擇需要保存文件/文件夾的路徑,並顯示,
step 2:創建文件夾
槽函數代碼:
//step 1 :選擇獲取路徑 QString m_srcDirPath = QFileDialog::getExistingDirectory( this, "choose src Directory", "/"); if (m_srcDirPath.isEmpty()) { return; } else { qDebug() << "srcDirPath=" << m_srcDirPath; m_srcDirPath += "/"; ui.label_path->setText(m_srcDirPath); std::string m_path = m_srcDirPath.toStdString(); //step 2 :創建Snap保存文件夾 temp_Path = m_path + "SnapImage/"; QString _SnapPath = QString::fromStdString(temp_Path); //創建文件夾 QDir *snapFile = new QDir; bool exist = snapFile->exists(_SnapPath); if (exist) { qDebug() << "exist" << _SnapPath; } else { //創建文件夾 bool ok = snapFile->mkdir(_SnapPath); //判斷是否成功 if (ok) { qDebug() << "ok"; } else { qDebug() << "no"; } } }