Arguments in Mac OS X

Discussion in 'Mac Programming' started by syamamoto, Dec 21, 2011.

  1. macrumors newbie

    Joined:
    Dec 21, 2011
    Location:
    Tokyo, Japan
    #1
    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
     
  2. macrumors 68040

    Joined:
    Apr 22, 2005
    #2
    Normally the application will call a method in it's delegate to tell it to open the file. It's not passed via argv.
     
  3. macrumors 603

    Joined:
    Aug 9, 2009
    #3
    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.
     
  4. syamamoto, Dec 22, 2011
    Last edited by a moderator: Dec 22, 2011

    thread starter macrumors newbie

    Joined:
    Dec 21, 2011
    Location:
    Tokyo, Japan
    #4
    Mac specific issue

    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
     
  5. macrumors 603

    Joined:
    Aug 9, 2009
    #5
  6. syamamoto, Dec 22, 2011
    Last edited by a moderator: Dec 23, 2011

    thread starter macrumors newbie

    Joined:
    Dec 21, 2011
    Location:
    Tokyo, Japan
    #6
    Arguments when a file is dropped

    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
     

Share This Page