I have a C++ application using the QT framework. 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.
As my main Mac reference, I'm using this Apple documentation. 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. 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.
According to this QT documentation I should be able to do this. 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. Things like LSSharedFileListRef are undefined. Is what I'm trying to do even possible from C++?
For the Carb开发者_运维百科on Apple Events API, I tried using the code that comes from Apple's own example. 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. Is this because I'm on 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?
If you want to support 10.4 and up, you need to use the 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. 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.
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.
精彩评论