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. Open file with double click on Mac
Forum Updated to NodeBB v4.3 + New Features

Open file with double click on Mac

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 4.9k Views 2 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.
  • S Offline
    S Offline
    Sikarjan
    wrote on 11 Jun 2017, 18:54 last edited by
    #1

    Hi, I am just reading up on how to open a file with my app on Mac OS X. Looks like it is a bit different from Unix and Windows. Is the answer from the last post still the correct and only way to do that? Or is there a better way that I could implement in my current code?

        QCommandLineParser parser;
        parser.setApplicationDescription(QCoreApplication::applicationName());
        parser.addHelpOption();
        parser.addVersionOption();
        parser.addPositionalArgument("file", "The file to open.");
        parser.process(app);
    
        MainWindow mainWin;
    
        if (!parser.positionalArguments().isEmpty()){
            QStringList files = parser.positionalArguments();
            foreach(QString path, files){
                path.replace(QString("\\"), QString("/"));
                mainWin.addEditor(path);
            }
        }else{
            qDebug() << "opening with no arguments" << argc << argv;
        }
        mainWin.show();
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Jun 2017, 20:05 last edited by
      #2

      HI,

      Take a look the QFileOpenEvent documentation, there's a full example on how to achieve what you want on macOS.

      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
      1
      • S Offline
        S Offline
        Sikarjan
        wrote on 11 Jun 2017, 20:17 last edited by Sikarjan 6 Nov 2017, 20:19
        #3

        Hmm, the reason why I was asking is that I already use QtSingleApplication which subclasses QApplication. Currently the single application code is not working on OS X and I hope I do not need to make this extra complicated by adding the event stuff...

        Regarding the plist modification. Do I have to do this manually every time or can I tell Qt Creator to a specific plist or add the required lines?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Jun 2017, 20:54 last edited by
          #4

          What exactly doesn't work on macOS ?

          From my experience QtSingleApplication does work on that platform.

          Create your own Info.plist and use QMAKE_INFO_PLIST.

          You can use an event filter if subclassing is too much of a hassle.

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

          M 1 Reply Last reply 11 Jun 2017, 21:36
          1
          • S SGaist
            11 Jun 2017, 20:54

            What exactly doesn't work on macOS ?

            From my experience QtSingleApplication does work on that platform.

            Create your own Info.plist and use QMAKE_INFO_PLIST.

            You can use an event filter if subclassing is too much of a hassle.

            M Offline
            M Offline
            mpergand
            wrote on 11 Jun 2017, 21:36 last edited by mpergand 6 Nov 2017, 21:44
            #5

            @SGaist said in Open file with double click on Mac:

            What exactly doesn't work on macOS ?

            From my experience QtSingleApplication does work on that platform.

            On OSX you can't launch the same application several times, so QtSingleApplication is useless.
            Catching the FileOpenEvent is the only way ...

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 11 Jun 2017, 21:44 last edited by
              #6

              @mpergand yes you can even though it's not particularly easy. Note it's also not overly complicated so use of QtSingleApplication is not useless if you want to ensure that one and only one copy of an application is running.

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

              M 1 Reply Last reply 11 Jun 2017, 21:48
              0
              • S SGaist
                11 Jun 2017, 21:44

                @mpergand yes you can even though it's not particularly easy. Note it's also not overly complicated so use of QtSingleApplication is not useless if you want to ensure that one and only one copy of an application is running.

                M Offline
                M Offline
                mpergand
                wrote on 11 Jun 2017, 21:48 last edited by mpergand 6 Nov 2017, 22:06
                #7

                @SGaist said in Open file with double click on Mac:

                @mpergand yes you can even though it's not particularly easy. Note it's also not overly complicated so use of QtSingleApplication is not useless if you want to ensure that one and only one copy of an application is running.

                The only way that I know is to make a copy of an application with a different name.
                [edit]
                It's also possible with the 'open' command from the terminal. (suprisingly !)

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sikarjan
                  wrote on 12 Jun 2017, 08:32 last edited by
                  #8

                  @SGaist thanks again for the help. I modified the QtSingleApplication to look for the open event. It seems to work on Windows and OS X now. I am not sure why the single application class did not work on Mac. At first I had issues that lockfile and lockfile_unix were loaded at the same time with the same functions. Then the app crashed because the signal did not work.
                  After copying the files forth and back between my Mac and Windows laptop it suddenly worked. I probably made a mistake with cleaning the project and rebuilding it after I copied the files.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    ghart976
                    wrote on 25 Jan 2024, 19:31 last edited by
                    #9

                    I recently encountered an interesting problem when working with Zsh and wanted to share my experience and ask for advice from the community.

                    S 1 Reply Last reply 25 Jan 2024, 19:37
                    0
                    • G ghart976
                      25 Jan 2024, 19:31

                      I recently encountered an interesting problem when working with Zsh and wanted to share my experience and ask for advice from the community.

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 25 Jan 2024, 19:37 last edited by
                      #10

                      @ghart976 hi and welcome to devnet,

                      You should either give more details or better: open a new thread about the topic you want to discuss. This one is 7 years old and not related to zsh at all but Finder.

                      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
                      0
                      • G Offline
                        G Offline
                        ghart976
                        wrote on 31 Jan 2024, 05:36 last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • J.HilkJ J.Hilk locked this topic on 31 Jan 2024, 06:39

                        • Login

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