utf-8qt4qdir

Creating a directory with a name containing UTF-8 characters in Qt


I am trying to create a directory that contains a UTF-8 characters using QDir::mkpath . A directory is created but the name is not correct. I am using this sample code:

#include <QCoreApplication>
#include <QDir>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString path = QDir::homePath();
    path += QDir::separator();
    path += "محمود";
    QDir().mkpath(path);
}

Solution

  • I solved my problem by replacing

    path += "محمود";
    

    by

    path += QString::fromUtf8("محمود");