argv parameter not received on mac

  • Hello everyone.

    I am trying to get the filename using my custom application by double clicking on the file.
    I am using the following code on Windows and Linux and the application logs the filename as a parameter on my log file. But on Mac it doesn't work. Can you point me where I am wrong or what else do I have to do on Macs?

    Also, using normal C++ console code on Mac, I receive an extra -PSN_xxx which doesn't appear on QT

    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QFile file("/example.txt");
        if(! |
            qDebug() << " Could not open file for writing";
            return 0;
        QTextStream out(&file);
        out<<"argc"<<argc<< endl;
        for (int i =0; i<argc; i++){
               out<<argv[i] << endl;
    // rest of the code

    Help appreciated

  • Moderators

    @chilarai said in argv parameter not received on mac:

    QFile file("/example.txt");

    the problem is not the arg[] but your file name /path,

    define a proper cross platform path for your log file and you're good to go

  • Hey thanks for the reply. The path is just an example. It does write the argv[0] parameter. But not the other parameters

  • Mac's finder does not append the name of the file as an argument to the application as Windows and most linux desktop environments. You have to handle an event:

  • Awesome. Thats what i was looking for. Thank you so much

  • Lifetime Qt Champion


    Just in case, you can get the list of parameters from your application instance using the arguments method.

Log in to reply