[Qt-interest] how to copy any app bundle on MacOS from one location to the other using QT methods?
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Tue May 18 15:59:59 CEST 2010
Serge wrote on Tuesday, May 18, 2010 3:25 PM:
> > ...
> can i use in my qt program:
> cp -r
Well, you could, but I personally don't like the idea of calling "external processes" do manipulate files (the "cp -r" was merely a placeholder, to explain the simple idea ;). Qt offers you all you need to manipulate files:
http://doc.trolltech.com/4.6/qfile.html
http://doc.trolltech.com/4.6/qdir.html
Implement your own little "tree traversal" algorithm, take a moment to think about how to copy symbolic links and remember to list/copy hidden files as well and there you go. :)
If you really insist on calling "cp -r" use http://doc.trolltech.com/4.6/qprocess.html
> how can i check result of it? was copy successfull or not?
Refer to the man(ual) page of 'cp' (http://unixhelp.ed.ac.uk/CGI/man-cgi?cp), I guess it returns 0 on success and anything else on failure. Also study the arguments (e.g. how to proceed with symbolic links - if there are any in application bundles anyway, not sure) of "cp" and pass them along with the help of QProcess.
The simplest (and most naive and errorprone) solution could be as simple as (not tested):
QStringList args;
args << "-r"; // think about -s argument here: "make symbolic link instead of copying"
args << "/path/to/app/bundle.app";
args << "/path/to/destination/";
int res = QProcess::execute("cp", args);
if (res != 0) {
// handle failure
}
But then again, take a deep thought about the previous post from Kustaa Nyholm (" A little googling exposes that there is something like a bundle bit and that Finder uses several strategies in identifying bundles."), he has a valid point that "application bundles" might be a bit more than just "a directory with the .app extension"!
I must admit that I fully trusted "The Internet" here as Source Of Wisdom (or more specific: http://en.wikipedia.org/wiki/Application_Bundle: "This file is really a directory ending in a .app extension.") ;)
Me being a Mac user since beginning of this year only I know that every directory contains at least two hidden files which names I can't remember right now. One of them stores the locations of all the icons for example. So maybe the Finder uses these hidden files as well as to tell whether a directory is an "app bundle" or not? Or maybe there is really that "app bundle property" in the file system which tells the Finder "Hey, this is an app bundle".
Then again qmake also creates "app bundles" for you, you could just investigate what that build step actually does (e.g. calling a system command, as to set some file properties?).
But maybe you don't need to worry about all this anyway, maybe a simple "cp -r" does the job anyway (in whatever concrete implementation form). :)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list