Windows Power State change event notification in Qt
I developing a GUI in QT where I have to show the battery status icon. To get the system power status, I am using the windows API. But to show status anytime , do i need to use a thread to continuously read and display the power status?
I am thinking of using event handler. But not sure how to implement. I am thinking 开发者_如何学Pythonthat for just one status icon I will run a thread. Anybody has any better suggestion, please share.
Using a thread might be a overkill, but using a timer might be much more suitable for this case.
QTimer can be used to update battery status on given interval. Just create QTimer object and connect it's timeout() signal to slot in your object, perhaps in some battery state widget. In this slot you just read the new state and update icon accordingly. Start QTimer instance with interval of your choice in milliseconds.
Btw. Qt Mobility API can be used to read power state also on desktop. Anyway if porting is not an issue, it might be easier just to use API that platform already provides.
精彩评论