Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Computer falls asleep while Qt Creator is building a large project



  • I am coding FreeCAD on Windows with Qt Creator 4.13.0. A full build of FreeCAD takes more than 25 minutes, and if i leave my laptop unattended, it falls asleep, suspending the build.

    It kinda sucks when I leave the laptop compiling, and then come back to find out that laptop fell asleep and FreeCAD isn't even halfway compiled. It would have been nice if Qt Creator could prevent the computer from auto falling asleep until the build is finished.

    I have looked through the settings of Qt Creator, and have not found anything for that. Is it possible?

    If someone is going to implement it, on windows it can be controlled by SetThreadExecutionState function.


  • Moderators

    Please report this on Qt bugtracker.



  • @DeepSOIC said in Computer falls asleep while Qt Creator is building a large project:

    it falls asleep

    LOL, sorry, couldn't help chuckling! Maybe it finds compiling boring ;-)



  • @sierdzio created https://bugreports.qt.io/browse/QTCREATORBUG-24682
    oh, and by the way, i forgot to say. Qt Creator is great!



  • Unfortunately, the tracker ticket was promptly closed =(
    Oh, well, i guess i have to up my idle timer.


  • Moderators

    Shame. I think it would have been a useful feature.



  • It doesn't seem like the right/responsibility of a compiler or maker or builder to keep a computer awake so it keep going. I assume if you want something like this you would need a "governor" service which you told what you wanted to keep awake for from running programs, and prevent sleep of that can be done?



  • @JonB
    i'm sure it can be done with a special governor... but being yet another perpetual background process, this solution for me is ugly at best.
    My computer doesn't sleep when i talk on skype. I don't have to set up a governor for that, it just works.
    My computer plays youtube for however long i like, there is no governor for that. Or plays music.
    My computer controls a 3d-printer, doesn't sleep, there is no governor (though i usually still change the power plan to "never sleep" for this very important occasion, for good measure)

    BTW, Moderns Standby in windows gives me trouble with the music playback (still falls asleep), but that's a topic for another discussion.



  • @DeepSOIC
    Hmm, I didn't know about those not being affected by or blocking sleep.

    So how do each of those work to achieve that?


  • Moderators

    @JonB as OP mentioned in the bug report:

    On windows, idle sleep can be prevented by calling SetThreadExecutionState Windows API function.



  • @sierdzio
    @DeepSOIC wrote:

    My computer plays youtube for however long i like

    I may [well] be old-fashioned, but I am assuming this means through a web browser, not some "app"(?). In which case, are you saying Google Chrome is making this SetThreadExecutionState call?


  • Moderators

    @JonB said in Computer falls asleep while Qt Creator is building a large project:

    @sierdzio
    @DeepSOIC wrote:

    My computer plays youtube for however long i like

    I may [well] be old-fashioned, but I am assuming this means through a web browser, not some "app"(?). In which case, are you saying Google Chrome is making this SetThreadExecutionState call?

    Yes, Chrome. It's really nothing exotic. It's part of WinApi since Windows XP. link



  • @sierdzio
    OK, so, don't shoot me, I'm just asking/suggesting: to get the desired behaviour, can the OP write a one-line wrapper around the compiler or make command, or perhaps the invocation of Qt Creator itself, to call the desired SetThreadExecutionState? It seems it doesn't matter which application that comes from, so long as that application is running, so any wrapper should do it?


  • Lifetime Qt Champion

    @JonB
    Hi
    Yes it works with any tool that sets this.
    like this one
    https://sourceforge.net/projects/coffeeff/files/
    that can see if Creator is running and then do it.



  • @JonB
    Firefox clearly does call that function while playing youtube. I can see it by executing powercfg -requests from elevated command prompt.

    DISPLAY:
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    [PROCESS] \Device\HarddiskVolume3\Program Files\Mozilla Firefox\firefox.exe
    
    SYSTEM:
    [DRIVER] Realtek High Definition Audio (INTELAUDIO\FUNC_01&VEN_10EC&DEV_0294&SUBSYS_10431AF1&REV_1000\4&298c7770&0&0001)
    An audio stream is currently in use.
    
    AWAYMODE:
    None.
    
    EXECUTION:
    None.
    
    PERFBOOST:
    None.
    
    ACTIVELOCKSCREEN:
    None.
    

    Winamp does not, apparently, but if only classic sleep (S3) is available, any audio stream keeps the computer awake. On modern sleep (S0), my laptop will sleep when winamp is playing, and it sucks (i have gone through hell to disable S0 on windows 10 v2004, maybe i should have ditched winamp instead).



  • @JonB said in Computer falls asleep while Qt Creator is building a large project:

    to get the desired behaviour, can the OP write a one-line wrapper around the compiler or make command, or perhaps the invocation of Qt Creator itself, to call the desired SetThreadExecutionState? It seems it doesn't matter which application that comes from, so long as that application is running, so any wrapper should do it?

    I think it should work. Adding a wrapper for Qt Creator is a bad idea, because i do want my computer to sleep if qt creator is just sitting there doing nothing. But a wrapper around msvc or ninja or maybe even cmake will most likely work.



  • @DeepSOIC
    Point taken! And interesting to know.

    IMHO only, this should not be done by a compiler. And this is all very Windows-specific, while Qt Creator and other Qt stuff is very much platform-independent.

    [I wonder whether Visual Studio even bothers to do this. I doubt the MSVC compiler does.]

    The bug report was rejected as "Out of Scope" for Qt, which it seems to me it indeed is. @mrjj's link or a one-liner wrapper seems to me the right way to go if you want this, and evidently it's all you can do since Qt devs are making clear they're not going to do it!



  • @DeepSOIC said in Computer falls asleep while Qt Creator is building a large project:

    Adding a wrapper for Qt Creator is a bad idea, because i do want my computer to sleep if qt creator is just sitting there doing nothing. But a wrapper around msvc or ninja or maybe even cmake will most likely work.

    Yes, absolutely. And in any case it's all you can do from here to get what you want :)



  • @JonB said in Computer falls asleep while Qt Creator is building a large project:

    And this is all very Windows-specific, while Qt Creator and other Qt stuff is very much platform-independent.

    I don't think the issue itself is platform-specific. SetThreadExecutionState is of course windows-specific. I'm not familiar with linux, macos, chromeos, android, ios. I see some info on macos and linux here: https://stackoverflow.com/questions/31498114/how-to-programmatically-prevent-linux-computer-from-sleeping-or-turning-on-scree

    I don't know if the computer will sleep when building a big project with qt creator on any other platform. But I suppose it will.



  • @DeepSOIC
    Well, that question shows there isn't anything commonly accepted for Linux?

    Let's perhaps agree on the following: if the Qt library does not offer a cross-platform anti-sleep (it does not, does it?) then Qt Creator is unlikely to make such a call! Perhaps the first thing would be to lobby for such a method being available from Qt!? :)



  • @JonB said in Computer falls asleep while Qt Creator is building a large project:

    Perhaps the first thing would be to lobby for such a method being available from Qt!? :)

    Yes, if there isn't one already.


  • Lifetime Qt Champion

    @JonB said in Computer falls asleep while Qt Creator is building a large project:

    hen Qt Creator is unlikely to make such a call!

    Why not? You can still do platform specific calls if available. In this case QtCreator Windows build would call this Windows specific API.



  • @jsulm
    Then that is "semi-sad", because if Qt Creator thinks it's worth doing whatever --- in this case, setting up for no-sleep --- and finds it has to make a platform-specific call, then the devs might think "other people might want to do this, so we'll make sure there is a Qt library support for it so others can utilise it".

    Of course it's not an absolute requirement. But it's an indication this might be worthwhile. I semi-hope (yes, within reason!) that the whole of Creator can be written using only Qt calls, not platform-specific ones. IMHO.


Log in to reply