简体   繁体   English

访问Cocoa和/或Carbon,以在OS X上启动时自动启动(在C ++上也使用QT)

[英]Access Cocoa and/or Carbon to automatically start on boot on OS X (on C++ also using QT)

I have a C++ application using the QT framework. 我有一个使用QT框架的C ++应用程序。 I'm trying to add an option for the user to be able to set the program to start automatically on startup. 我正在尝试为用户添加一个选项,使其能够将程序设置为在启动时自动启动。

My development machine is running OS X 10.6. 我的开发计算机正在运行OS X 10.6。

As my main Mac reference, I'm using this Apple documentation . 作为主要的Mac参考,我正在使用此Apple文档 According to the documentation, there are two recommended ways of doing this. 根据文档,有两种推荐的方法。 One is to use the Cocoa Shared Files List API, which works only on OS X 10.5 or higher. 一种是使用仅在OS X 10.5或更高版本上有效的Cocoa共享文件列表API。 The other is to use the Carbon Apple Events API, which while not explicitly stated in the documentation, from my readings appears to work only on OS X 10.5 or lower. 另一种方法是使用Carbon Apple Events API,尽管我的阅读资料中没有明确说明,但据我看来,该API仅适用于OS X 10.5或更低版本。

According to this QT documentation I should be able to do this. 根据此QT文档,我应该能够做到这一点。 However, I can't seem to figure out how to make either of these methods work. 但是,我似乎无法弄清楚如何使这两种方法都起作用。

For the Cocoa Shared Files List API, I followed the suggestions from this answer , but I can't seem to figure out what files to include that will get this working in my project. 对于Cocoa共享文件列表API,我遵循了此答案中的建议,但似乎无法弄清楚要包含哪些文件才能使它在我的项目中正常工作。 Things like LSSharedFileListRef are undefined. 像LSSharedFileListRef这样的东西是未定义的。 Is what I'm trying to do even possible from C++? 我想用C ++做的事情甚至可能吗?

For the Carbon Apple Events API, I tried using the code that comes from Apple's own example . 对于Carbon Apple Events API,我尝试使用来自Apple 自身示例的代码。 However, including doesn't seem to define all the things I need like all the examples online seem to suggest. 但是,包括似乎并没有定义我需要的所有东西,就像在线上的所有示例所暗示的那样。 For example, DescType is undefined, and the examples don't work. 例如,DescType是未定义的,示例不起作用。 Is this because I'm on OS X 10.6? 这是因为我使用的是OS X 10.6吗?

Overall, what can I do to get my program to start on boot, ideally supporting all Macs OS X 10.4 and up? 总体而言,我该怎么做才能使程序在启动时启动,并且理想地支持所有Mac OS X 10.4及更高版本?

If you want to support 10.4 and up, you need to use the Carbon Apple Events API. 如果要支持10.4及更高版本,则需要使用Carbon Apple Events API。

The sample code you linked to worked on my OS X 10.6 box works without any problem, if you set the base SDK to 10.4u or 10.5. 如果将基本SDK设置为10.4u或10.5,则链接到我的OS X 10.6盒子上的示例代码可以正常工作。 There are a few lines you need to remove if you want to compile it with 10.6 SDK, but if you want to support 10.4 and up, that's not what you want. 如果要使用10.6 SDK进行编译,需要删除几行,但是如果要支持10.4及更高版本,那不是您想要的。

By the way, a user can easily set up a program to launch at the login time, by using the Account pane of the System Preferences. 顺便说一句,用户可以使用“系统偏好设置”的“帐户”面板轻松设置要在登录时启动的程序。 So, I don't think any need for you to provide the check box yourself. 因此,我认为您不需要自己提供复选框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM