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

 

posted @ 2021-08-05 10:30  手磨咖啡  阅读(2031)  评论(0编辑  收藏  举报