c++ - QT - copying a file to AppData -
my program prompts user select file process. program processes , tries save file appdata.
this how it:
qsettings settings(qsettings::iniformat, qsettings::userscope, "flametool", "flametool"); addin_path = qfileinfo(settings.filename()).absolutepath() + "/addins/" + id + ".limod" ; qdebug(addin_path.tolocal8bit()); if(qfile::copy(qdir::tonativeseparators(file_passed),qdir::tonativeseparators(addin_path))) qdebug("copied"); else qdebug("not copied");
everytime part of code executed, outputs "not copied". how can copy file?
in order want, advice using qstandardpaths class instead:
set application name in, example, main.cpp
int main(...) { [..] a.setapplicationname("flametool"); }
copy file:
qstring addin_path = qstandardpaths::writablelocation(qstandardpaths::datalocation); qdir dir(addin_path); if (!dir.exists()) dir.mkpath(addin_path); if (!dir.exists("addins")) dir.mkdir("addins"); dir.cd("addins"); addin_path = dir.absolutefilepath(id + ".limod"); if (qfile::exists(addin_path)) qfile::remove(addin_path); if(qfile::copy(file_passed, addin_path)) qdebug("copied"); else qdebug("not copied");
please note that:
note if file name newname exists, copy() returns false (i.e. qfile not overwrite it).
Comments
Post a Comment