QTimer elapsed time



  • Hello All,

    I am doing some OpenGL programs in Qt.

    Actually I have

    @ QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->start(100);@

    in one class

    On a button-press also, I am calling update() to redraw the geometry.

    Now What I want to do is draw only few things on a button press, and other as per QTimer's evaluations.
    but I can not call directly only those functions which are to be drawn on button-press, simply because they are dependent on not-to-be-drawn geometry.

    Another thing is that above code of QTimer is in different class and decision of what to draw is to be made in different class. (Some people may think this is C++ question rather than plain Qt; --)

    So how do I go about it..?
    Do I need to manually put current time in one variable and check for time passed since that value and then do things..and that too irrespective of Qtimer? ?

    Thanks
    Andrew



  • If I understand correctly, you want to do the following:

    • Whenever a timer event occurs: Redraw everything

    • When the user presses a button: Redraw only some things

    First question: Why?
    Is it a matter of content, or of performance?

    If it is a matter of content, it might be better to design your data structures so that you can always draw the state of the previous timer event, plus the few changes made by the button.

    If it is a matter of performance, I would check if it really is, because at 100 ms timer interval, you shouldn't get too many button clicks in between.



  • Yes, it is matter of content.

    And about redesigning structure of classes, I do not think it is smart idea. Because if I do that I need to put everything inside one class only. It becomes unmanageable

    Actually problem is not that I am missing some events. To put it in another way --> I want some geometry to be drawn slowly and other immediately after a button press..



  • For one thing, it wouldn't have to be a single class. It could be a tree-like structure of classes that represent the content of whatever you draw. I've done this several times, with fairly complex data. It's a lot of work, but I find it's worth it.

    Otherwise, you'd have to basically paint something "on top of what you already have". This might or might not work, depending what you want to paint "on top".

    Will all the things painted when the button is pressed be on top of the rest? If yes, you can paint your complex geometry into a back buffer, a pixmap that you simply paint below your "extra data", or a GL display list.
    If the things you want to draw on a button press are intermixed with everything else, things could get nasty, however.


Log in to reply
 

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