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

How to set Application Execution Priority to High.



  • Hi, I need to set my application execution priority to high, as we do in Task Manager (Screenshot attached below for reference) is it possible to set app execution priority to high in the code or settings? Kindly help me.

    Screenshot (29).png



  • @Rajesh-Panati
    This is outside the scope of Qt, and is also completely OS-dependent. (You should not be allowed to raise the priority of a program within itself, and Linux at least won't let you do it.) Windows Task Manager is presumably a privileged/elevated running program, which allows it to alter other process's priorities. Goodness knows whether raising a process's priority has any real, noticeable effect under Windows.

    You may be able to achieve something under Windows by looking at QThread::currentThread()->setPriority(), but I'm not sure that does anything for the application as a whole. You could also look at SetPriorityClass Win32 function; again, I don't know whether you can raise your own, already-running priority.



  • Hi @JonB Ok. Thank you for your quick response. Wanted know if this can be achieved within QT.

    Regards,

    Rajesh P



  • Setting priority of the current process can be done in Window's API

    SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
    

    But not in Qt, Qt only provides setting priority of QThread.



  • @Bonnie
    Which is what I suggested: so Windows does allow a process to boost its own priority, without any non-default/elevated privileges? In which case, it wouldn't surprise me if loads of applications might do this, everyone thinks their program is more important than anyone else's! ;-)



  • @JonB Hmm..I'm not sure how does Windows handle this priority thing.
    But if you have the above code executed in your app, it does show as "High Priority" in Task Manager.



  • Hi, @Bonnie Thank you for the response. will try it.


Log in to reply