Results 1 to 6 of 6

Thread: Qt file copy issue, treating the copied file is text document only not as exe

  1. #1
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt file copy issue, treating the copied file is text document only not as exe

    I am copying a certail file from one path to another using the below code

    Qt Code:
    1. QString curdir = QCoreApplication::applicationDirPath().append("/db_ssparkl.sqlite");
    2. profileName= qd.homePath().append("/ssparkl.sqlite");
    3. QFile dbfile;
    4. QFile destifile;
    5. destifile.setFileName(profileName);
    6. dbfile.setFileName(curdir);
    7.  
    8. if(dbfile.exists() && !destifile.exists())
    9. {
    10. bool success = true;
    11. success &= dbfile.open( QFile::ReadOnly );
    12. success &= destifile.open( QFile::WriteOnly | QFile::Truncate );
    13. success &= destifile.write( dbfile.readAll(),dbfile.size()) >= 0;
    14. destifile.close();
    15. dbfile.close();
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    I am writing by reading the source file content onto destination file content, since QFile::copy didn't work as expected as the file copied show size as zero bytes.


    Now the file is getting copied fully as expected. But it's being treated text document and not as exec(app)

    How to make it treated as app.


    Added after 9 minutes:


    I googled it and found that, after writing the file has to be given +x option.

    chmod +x filename

    how do I do this in QT


    Added after 16 minutes:


    Got it solved as below

    Qt Code:
    1. QString changeToExec = "chmod +x "+destifile.fileName();
    2. QProcess::execute(changeToExec);
    To copy to clipboard, switch view to plain text mode 
    Last edited by ejoshva; 10th April 2015 at 11:37.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt file copy issue, treating the copied file is text document only not as exe

    You should retry QFile::copy() and figure out what does not work, because your approach is much more fragile. You have no way of knowing whether you successfully read the whole input file and no way of knowing whether you successfully wrote the whole data to the output file (remember, QIODevice::write() write some bytes, but maybe not all of them). Your approach does not scale well because you copy the whole file in memory instead of copying it by fixed-sized chunks. By the way, you should use "&&=" instead of "&=".

    To answer your question, call setPermissions() on your target QFile and make sure you include ExeOwner (and possibly other Exe* constants) in the permissions.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt file copy issue, treating the copied file is text document only not as exe

    Quote Originally Posted by ejoshva View Post
    How to make it treated as app.
    Why? Its filename suggests that it is an SQLite database file, not a program.

    Cheers,
    _

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt file copy issue, treating the copied file is text document only not as exe

    Indeed, the execute privilege makes no sense at all on a data file like this appears to be. If it is actually an executable then copying it to a user modifiable location seems an odd thing to do.

    Setting that permission can be done more efficiently with QFile::setPermissions(), just as the original copy can be done with QFile::copy()
    Last edited by ChrisW67; 10th April 2015 at 21:02.

  5. #5
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt file copy issue, treating the copied file is text document only not as exe

    Thought Its a program , it's not treating as a program. Its just treating as an document with only read,write permission.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt file copy issue, treating the copied file is text document only not as exe

    Quote Originally Posted by ejoshva View Post
    Thought Its a program , it's not treating as a program.
    So it is not an sqlite database? What does command "file ssparkl.sqlite" print out?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Cannot copy js file from resource to file system
    By kalma in forum Qt Programming
    Replies: 1
    Last Post: 1st January 2015, 15:10
  2. Replies: 7
    Last Post: 3rd February 2014, 14:27
  3. Replies: 2
    Last Post: 28th October 2011, 07:46
  4. Replies: 0
    Last Post: 2nd August 2010, 09:37
  5. Replies: 0
    Last Post: 11th May 2009, 08:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.