Multiple QTimers or Multiple Connects to same QTimer

  • Hi,

    I am on a development team of a new Qt application that requires several polling loops to: update status, update some objects on displays based on changes, read messages as they arrive, send requests to other computers, etc, etc. We have been trying to decide whether to use 4 QTimers, each at different intervals (1, 2, 5, 10 seconds) and connect maybe 5 slots to each, OR to use multiple QTimers, and end up with 20 QTImers firing, some at the same interval.

    Anybody have an opinion on the better way to go?

    Thanks in advance.

  • Moderators

    Hi, welcome to devnet

    It's hard to say which one is "better". My feeling is you won't see much difference one way or the other.
    Qt is really designed in a more action-reaction style. Although I don't know what your app is about I can say that any sort of polling is usually wasteful as it re-does a lot of the same work over and over.
    The more Qtish design is to respond to events and connect to signals - so do something in reaction to something: Update status when it changes, not in intervals. Update display when underlying data changes, not check for it periodically. Create message (or event) handlers instead of checking if some arrived and so on.
    All this is of course theoretical without a more detailed info.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.