Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStandardPath::writeableLocation() Permission denied?
Forum Updated to NodeBB v4.3 + New Features

QStandardPath::writeableLocation() Permission denied?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstandardpathwriteablelocatiwindows7
3 Posts 2 Posters 1.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • the_T Offline
    the_T Offline
    the_
    wrote on last edited by
    #1

    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 of QStandardPaths::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?)

    -- No support in PM --

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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_T 1 Reply Last reply
      0
      • mrjjM mrjj

        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_T Offline
        the_T Offline
        the_
        wrote on last edited by
        #3

        @mrjj

        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.

        -- No support in PM --

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved