Hello. I did not find the answer in Google, I decided to ask here. Tell me where the error crept in.

QFile file; QString f = "/mnt/tmpfs/"; f += n; f += ".txt"; // проверяем наличие файла на месте if (QFile::exists(f) == false) // проверка на существование { file.setName(f); // создали файл if (QFile::exists(f) == false) qDebug () << error(3); } 

Gives an error message.

 error: 'class QFile' has no member named 'setName' file.setName(f); // создали файл ^ 
  • one
    Why google when there is official documentation? - Vladimir Martyanov

1 answer 1

To create a file, you need to call functions in sequence:

 void QFile::setFileName ( const QString & name ) bool QFile::open(OpenMode mode) 

It turns out the following code

 QFile file; QString f = "/mnt/tmpfs/"; f += n; f += ".txt"; // проверяем наличие файла на месте if (QFile::exists(f) == false) // проверка на существование { //имя файла file.setFileName (f); // создаем файл if (!file.open(QIODevice::WriteOnly)) { qDebug () << error(3);//ошибка создания } } 
  • Thank you. I took info from qt-doc.ru/rabota-s-fajlami-klass-qfile.html as it turned out I had to write setFileName in the place setName - shaman888
  • @ shaman888 just 5 years have passed ... - Vladimir Martyanov
  • @ Vladimir-Martyanov I did not understand you. - shaman888
  • 2
    @ shaman888 What is incomprehensible? It is necessary to read current manuals. doc.qt.io/qt-5/qfile.html - Evgeny Borisov
  • @ shaman888 article, according to which you did something 5 years ago. - Vladimir Martyanov