Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Cannot create directory and write text file

$
0
0
I have encounted the following problem. My system is window 8. 1. To create a folder I always have to constant declare the folder name before created the folder. I cannot used the parameter QString to created the folder but when I used the folder_1 , the required folder is created. 2. The following code always crash my program. I cannot find where the problem is. Hope somebody can help me. QString LibFileIO::writeTextFile( QString folder, QString filename , QStringList TextContent ){     bool no_error = true;       // This will work. If I used the parameter folder it will not be created.     QString folder_1 = "C:/wamp/www/test_ikeepintouch_com/laravel/app/views/hello";     QDir dir( folder_1 );       if( dir.exists() == false ){         if( dir.mkdir( folder_1 ) == false ){             qDebug() << " Directory cannot be created = " + folder_1;         }else{             qDebug() << " Directory created = " + folder_1;         };     }       QFile file( folder_1 + "/" + filename );     file.open( QIODevice::WriteOnly | QIODevice::Text );     if( file.isOpen() == false ){         qDebug() << " Error open file " + file.errorString();         return file.errorString();     }       QTextStream out(&file);     foreach( QString str , TextContent ){        out << "HELLO";     }       qDebug() << " Closing" ;     // optional, as QFile destructor will already do it:     out.flush();     file.close();   } //=============================================================   #ifndef LIBFILEIO_H #define LIBFILEIO_H   #include <QObject> #include <QString>   class LibFileIO : public QObject {     Q_OBJECT public:     explicit LibFileIO(QObject *parent = 0);     static QString writeTextFile(  QString folder, QString filename , QStringList TextContent ); signals:   public slots:   };   #endif // LIBFILEIO_H

Viewing all articles
Browse latest Browse all 13965

Trending Articles