qt - Create sub-directory and inserting file in it -


i've tried create folder , insert file in or create file in it. here code snippit:

qdir dir; qstring filepath(qcoreapplication::applicationdirpath() + "/"                + dir.mkdir("logs")+ "/" + "file.txt");  qfile* file = new qfile(filepath); qtextstream stream; stream.setdevice(file);  bool check = file->open(qiodevice::writeonly | qiodevice::text | qiodevice::append);  if(check) {     stream << "....text....\n";     stream.flush();     file->close(); } delete file; 

there no error while compiling rather, creates folder without file in it. how can that?

qstring filepath(qcoreapplication::applicationdirpath() + "/"                + dir.mkdir("logs")+ "/" + "file.txt"); 

i suspect line, dir.mkdir("logs"), create directory , return true or false. not sure final path.

i suggest following.

if(!dir.mkdir("logs")){ //error return ; }  qstring filepath(qcoreapplication::applicationdirpath() + "/"                    + "logs"+ "/" + "file.txt"); ... 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -