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. [SOLVED] QTimer and AppNap on OS X 10.9 Mavericks with Qt 4.8.5

[SOLVED] QTimer and AppNap on OS X 10.9 Mavericks with Qt 4.8.5

Scheduled Pinned Locked Moved General and Desktop
26 Posts 9 Posters 14.6k Views
  • 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.
  • G Offline
    G Offline
    godzaman
    wrote on 4 Feb 2014, 01:21 last edited by
    #12

    Thanks,

    Done that, no errors, no warnings, no linker problems, everything compiles and runs...

    ... but app does enter "app nap" mode, and i debugged it, it executes the nsprocessinfo beginwithactivity method, but after a while (3-4) minutes, app goes into nap again. Maybe there is a time limit for activity :|

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Feb 2014, 21:52 last edited by
      #13

      I haven't seen something like that but I may have missed it.
      Do you have an operation that takes that long ? Or is it one short that you repeat ?

      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
        godzaman
        wrote on 5 Feb 2014, 02:19 last edited by
        #14

        well, it's a timer app that can run in background for hours and while timer is active, app should not enter app nap because as app is programmed currently (not by me) timer executes every second and counts those seconds as a total timer duration. I know it's better to remember only timestamps and then calculate number of seconds passed, but we don't have time right now for bigger refactoring, as this needs to be quick fix.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Feb 2014, 07:52 last edited by
          #15

          One other thing that you can try then is use QProcess when starting your application and run this command

          @defaults write <app domain name> NSAppSleepDisabled -bool YES@

          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
            godzaman
            wrote on 5 Feb 2014, 17:21 last edited by
            #16

            @SGaist thank you a lot. I think this solved the issue. I'm really grateful for time you spent helping me.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 5 Feb 2014, 22:24 last edited by
              #17

              You're welcome !

              Now that your application doesn't go to sleep anymore, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              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
                godzaman
                wrote on 5 Feb 2014, 23:13 last edited by
                #18

                Deal! Thanks again.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rwinchester
                  wrote on 24 Feb 2014, 19:02 last edited by
                  #19

                  Hi, after fighting this for days, I finally stumbled on the very helpful info from #SGaist, which appears to work great. One detail that baffled me: for some reason, NSAppSleepDisabled gets removed from my app's plist every time it quits. So, as he describes, you must re-set it each time you launch. A mystery to me.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    godzaman
                    wrote on 24 Feb 2014, 19:12 last edited by
                    #20

                    I came to same conclusion, set the NSAppSleepDisabled every time app starts. I know it's not the cleanest way, but it does the job.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      janfaroe
                      wrote on 16 Jul 2014, 20:08 last edited by
                      #21

                      Adding the following entry in the Info.plist file solved the problem for me:

                      @<key>LSAppNapIsDisabled</key>
                      <true/>@

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        droark
                        wrote on 14 Aug 2014, 22:26 last edited by
                        #22

                        Hello. I'll also go on the record and state that the LSAppNapIsDisabled entry in Info.plist seems to make Qt more responsive in certain situations. It's not a silver bullet; I'm still ironing out other issues. It is quite useful in general, though!

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mark_in_gr
                          wrote on 2 Oct 2014, 20:50 last edited by
                          #23

                          How were you able to get the "defaults write <app domain name> NSAppSleepDisabled -bool YES" to work with QProcess on the Mac? I have tried setting up a QProcess object using arguments and just the entire command as one string and it doesn't seem to set this properly. Yet when I run the same command from a Terminal, it sets it correctly.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mark_in_gr
                            wrote on 2 Oct 2014, 21:15 last edited by
                            #24

                            [quote author="janfaroe" date="1405541281"]Adding the following entry in the Info.plist file solved the problem for me:

                            @<key>LSAppNapIsDisabled</key>
                            <true/>@[/quote]

                            I've also tried this. Placing these entries in my .app plist file, restarting the app and after a time, the "App Nap" value changes to "Yes" in Activity Monitor.

                            The only way I can get App Nap to turn off is to use this command from the Terminal:

                            defaults -write _domain appname_NSAppSleepDisabled -bool YES

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              RJVB
                              wrote on 1 Dec 2014, 23:21 last edited by
                              #25

                              Anything you set in the Info.plist is read into the application's Info Dictionary, from where it is then used (or not...). I'm a bit surprised that calling defaults works from the application itself, but that probably means that the corresponding key/value pair is not read before entering the main function.

                              All that to say that there might be another solution which doesn't even involve ObjC (if could, but many ObjC classes are "toll-free bridged" with regular C types available through the CoreFoundation framework ;)).

                              Here's a bit of code I use to turn an application into an "agent" (i.e. something that can present widgets, like a systray icon+menu", but doesn't appear in the Dock or App Switcher, and doesn't get a global menubar).
                              (Replace Q_OS_MAC with Q_OS_OSX in Qt5)

                              @
                              #ifdef Q_OS_MAC
                              #include <CoreFoundation/CoreFoundation.h>
                              #endif
                              @

                              and then before creating the QApplication instance:

                              @
                              #ifdef Q_OS_MAC
                              CFBundleRef mainBundle = CFBundleGetMainBundle();
                              if( mainBundle ){
                              // get the application's Info Dictionary. For app bundles this would live in the bundle's Info.plist,
                              // for regular executables it is obtained in another way.
                              CFMutableDictionaryRef infoDict = (CFMutableDictionaryRef) CFBundleGetInfoDictionary(mainBundle);
                              if( infoDict ){
                              // Add or set the "LSUIElement" key with/to value "1". This can simply be a CFString.
                              CFDictionarySetValue(infoDict, CFSTR("LSUIElement"), CFSTR("1"));
                              // That's it. We're now considered as an "agent" by the window server, and thus will have
                              // neither menubar nor presence in the Dock or App Switcher.
                              }
                              }
                              #endif
                              @

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                RJVB
                                wrote on 1 Dec 2014, 23:21 last edited by
                                #26

                                Anything you set in the Info.plist is read into the application's Info Dictionary, from where it is then used (or not...). I'm a bit surprised that calling defaults works from the application itself, but that probably means that the corresponding key/value pair is not read before entering the main function.

                                All that to say that there might be another solution which doesn't even involve ObjC (if could, but many ObjC classes are "toll-free bridged" with regular C types available through the CoreFoundation framework ;)).

                                Here's a bit of code I use to turn an application into an "agent" (i.e. something that can present widgets, like a systray icon+menu", but doesn't appear in the Dock or App Switcher, and doesn't get a global menubar).
                                (Replace Q_OS_MAC with Q_OS_OSX in Qt5)

                                @
                                #ifdef Q_OS_MAC
                                #include <CoreFoundation/CoreFoundation.h>
                                #endif
                                @

                                and then before creating the QApplication instance:

                                @
                                #ifdef Q_OS_MAC
                                CFBundleRef mainBundle = CFBundleGetMainBundle();
                                if( mainBundle ){
                                // get the application's Info Dictionary. For app bundles this would live in the bundle's Info.plist,
                                // for regular executables it is obtained in another way.
                                CFMutableDictionaryRef infoDict = (CFMutableDictionaryRef) CFBundleGetInfoDictionary(mainBundle);
                                if( infoDict ){
                                // Add or set the "LSUIElement" key with/to value "1". This can simply be a CFString.
                                CFDictionarySetValue(infoDict, CFSTR("LSUIElement"), CFSTR("1"));
                                // That's it. We're now considered as an "agent" by the window server, and thus will have
                                // neither menubar nor presence in the Dock or App Switcher.
                                }
                                }
                                #endif
                                @

                                1 Reply Last reply
                                0

                                • Login

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