PDA

View Full Version : Arguments in Mac OS X




syamamoto
Dec 21, 2011, 09:43 PM
I am using Qt (Nokia) with X-Code. Once coded, it works with Windows, Linux, and in Mac OS X. However, double-clicking in the Finder or drag-and-dropping from the Finder works in a different way.

I supposed that the name of the file that was double-clicked or dropped is sent by the arguments in main( ) function such as:
int main( int argc, char *argv[] )
The name is usually stored in argv[1]. Alternatively, it is possible to get argument strings by QCoreApplication::arguments( ) as a QStringList. In Mac OS X, Finder seems to send some message in a fashon completely different form the ordinary methods.

Could someone tell me how to get the name of the data files that are sent from Finder by double-clicking or by dropping in Mac OS X. I am not using Objective C because it just works only with Mac OS X.

Thank you.

SYamamoto



admanimal
Dec 21, 2011, 11:37 PM
Normally the application will call a method in it's delegate to tell it to open the file. It's not passed via argv.

chown33
Dec 22, 2011, 11:31 AM
You should probably ask your question on a forum that specializes in Qt.


I googled the following search terms:
qt drag and drop
qt drag and drop files

The results show the basic Qt DnD reference doc, a mention of XDND protocol, and a nearly identical question from 2005:
http://www.qtforum.org/article/15340/drag-and-drop-file.html

which contains a link to this:
http://doc.trolltech.com/3.3/quridrag.html

I didn't spend more than about 2 minutes doing these searches. The important thing is to confine the search to Qt, since a correct answer must use only portable Qt features or capabilities. Asking how to do it on a Mac is misguided if the result needs to be portable.

syamamoto
Dec 22, 2011, 06:57 PM
You should probably ask your question on a forum that specializes in Qt.

Than you very much for your response. I am routinely using drag-and-drop mechanism in Qt and it works fine with Windows and Linux. I am familiar with the Qt reference pages you told me.

When a file is dropped on the application icon, the application starts at the enter point main( argc, argv ). In Windows and Linux, argv[1] contains the name of dropped file. This is not the case with Mac OS X. When an application in Mac is executed by a shell, it is possible to send the data file name to be opened but then it is not possible to send the file name from Finder to the shell.

Otherwise, Qt provides QCoreApplication::arguments( ) function and it also works with Windows and Linux. However, in Mac OS X, it just returns an empty string.

Therefore, what I want to know is simple. The method to know the file name dropped from Finder in Mac OS X. Probably this is not the problem of Mac OS X and I should find out the method in Qt functions. I tried to find out, but I could not get useful information. I rather considered that I have to solve this problem by Mac-specific method as is shown in
http://developer.qt.nokia.com/doc/qt-4.8/mac-differences.html

Thank you again.

syamamoto

chown33
Dec 22, 2011, 07:20 PM
I googled for:
qt mac files

One of the top results was this:
http://doc.qt.nokia.com/qq/qq12-mac-events.html

After reading the first few paragraphs, you should probably skip the rest of the article and scroll down to the bottom to read about the QFileOpenEvent (http://developer.qt.nokia.com/doc/qt-4.8/qfileopenevent.html) class.

syamamoto
Dec 22, 2011, 10:40 PM
I googled for:
qt mac files

Thank you very much. This information is what I have been looking for. I wonder why I could not find out the page!

I appreciate your kindness.

syamamoto