QT -- 獲取文件夾位置,並創建新的文件夾


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";
            }
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM