Open file with double click on Mac
-
wrote on 11 Jun 2017, 18:54 last edited by
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();
-
HI,
Take a look the QFileOpenEvent documentation, there's a full example on how to achieve what you want on macOS.
-
wrote on 11 Jun 2017, 20:17 last edited by Sikarjan 6 Nov 2017, 20:19
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?
-
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.
-
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.
wrote on 11 Jun 2017, 21:36 last edited by mpergand 6 Nov 2017, 21:44@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 ... -
@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.
-
@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.
wrote on 11 Jun 2017, 21:48 last edited by mpergand 6 Nov 2017, 22:06@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 !) -
wrote on 12 Jun 2017, 08:32 last edited by
@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. -
wrote on 25 Jan 2024, 19:31 last edited by
I recently encountered an interesting problem when working with Zsh and wanted to share my experience and ask for advice from the community.
-
I recently encountered an interesting problem when working with Zsh and wanted to share my experience and ask for advice from the community.
@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.
-
wrote on 31 Jan 2024, 05:36 last edited byThis post is deleted!
-
J J.Hilk locked this topic on 31 Jan 2024, 06:39