-1
我一直在試圖在Linux的根目錄下創建一個目錄。但由於我對Linux平臺不太熟悉,我無法在QT中編寫正確的程序。你能看看我的代碼,並告訴我我哪裏錯了嗎?如何在Linux中使用QT(QDir)創建目錄?
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QString>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QDir mDir;
QString mpath="/home/qtfile";
if (!mDir.exists(mpath))
{
mDir.mkpath(mpath);
qDebug() <<"Created";
}
else if (mDir.exists(mpath))
{
qDebug() <<"Already existed";
}
else
{
qDebug()<<"Directory could not be created";
}
return a.exec();
}
謝謝您的時間和考慮
編輯: - 謝謝大家。現在解決了這個問題
是'「/ \家\ qtfile」'也許應該是'「/家/ qtfile」 '? – Angew
@Angew我想我試過 –
我想你應該使用mDir.mkdir而不是mkpath – Dusteh