Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. argv parameter not received on mac
Forum Updated to NodeBB v4.3 + New Features

argv parameter not received on mac

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 569 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chilarai
    wrote on last edited by
    #1

    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[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
    
    
        QFile file("/example.txt");
        if(!file.open(QFile::WriteOnly |
                      QFile::Text))
        {
            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;
        }
        file.flush();
        file.close();
    
    // rest of the code
    

    Help appreciated

    J.HilkJ 1 Reply Last reply
    0
    • C chilarai

      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[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
          QGuiApplication app(argc, argv);
      
      
          QFile file("/example.txt");
          if(!file.open(QFile::WriteOnly |
                        QFile::Text))
          {
              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;
          }
          file.flush();
          file.close();
      
      // rest of the code
      

      Help appreciated

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • C Offline
        C Offline
        chilarai
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          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: https://doc.qt.io/qt-5/qfileopenevent.html

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          7
          • C Offline
            C Offline
            chilarai
            wrote on last edited by
            #5

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

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved