QStandardPath::writeableLocation() Permission denied?
-
Hi all,
In one of my applications I need to open files that are stored as blobs in a database. Therefore I save them in the path I get from
QStandardPaths::writableLocation(QStandardPaths::TempLocation)
.
If I read the doc ofQStandardPaths::writableLocation(StandardLocation type)
correctly, this returns me a QString with the path of writable the StandardLocation or empty string.But when I try to write a file to this location I get a "Permission Denied" Error on some Windows machines. even though I can create a file there when I open the location with the file browser and do right click -> new file
(On other windows and linux machines there is no problem to write the file into the TempLocation and open it with QDesktopServices)q.prepare("select * from attachments where ID=:id"); q.bindValue(":id",attid); q.exec(); q.first(); //the query is always valid and returns exact 1 row QByteArray fc; QString fn; fc = q.value("content").toByteArray(); fn = q.value("name").toString(); QFile f; f.setFileName(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/"+fn); qDebug() << f.errorString(); if(f.open(QFile::WriteOnly)) { f.write(fc); qDebug() << f.errorString(); f.close(); bool localOpenUrl = QDesktopServices::openUrl(QUrl::fromLocalFile(f.fileName())); if(!localOpenUrl) QMessageBox::warning(this,"Error","Failed to open attachment " + fn + "\n" + f.errorString()); } else { QMessageBox::warning(this,"Error","Failed to open " + f.fileName() + "\n" + f.errorString()); }
Any ideas or hints what could went wrong (or what I did wrong here) here? (Or any other ways how to open a binary blob from database with the per default program?)
-
Hi
Just a thought, some anti virus (like avast) sometimes block such files
if it seem suspicious to them.
On the pc that fails, will it fail all the time?Also, does it return same path on those pc?
I mean, is the Temp location the same across working/not working? -
The QMessageBox shows the same temp. location as i can see when i run
set
in the commandline. Its the default TempLocation used by Windows ("C:/Users/<USER>/AppData/Local/Temp").
And this piece of code always fails to write to this location on this PC.I will check for antivirus issues next time when i have access to this PC.