ubuntu - Qt can not respond key Press event immediately -
environment: ubuntu, qt creator
in qt app, found qt doesn't respond key press event immediately, if wait while, responds.
i think blocking ui.
as know, if qt's component (qwidget etc.) being destroyed, qt ui blocked. have checked code, there no component being destroyed @ time i'm pressing up/down key. want know there other things can block qt ui.
{ ... connect(webviewwidget, signal(loadfinished()), this, slot(additem())); ... } void additem() { delete webviewwidget; // delete block ui? mlistwidget = new scrollwidget(); mscrollarea = new scrollarea(this); for(int i=0; i<datalen; i++) { mlistwidget->addsubitem(itemwidget); } } void keypressevent(qkeyevent *event) { switch(event->key) { case up_key: scroll up; break; case down_key: scroll down; break; default: break; } }
destruction of objects not concern, unless doing lot of work in destructor. destroying webview may take long. should not destroying do. instrument delete (see code below) , see how long takes.
your own code may calling apis block. calling third party libraries? calling
wait...methods in qt's own api?if you're unsure, can instrument every slot , every reimplemented virtual method
xxxevent(...). you'd need instrument only slots , reimplemented qobject/qwidget methods, not every method in code.you may producing event storm, perhaps posting lots of events in loop, or sending lot of signals hooked slots connected via
qt::queuedconnection. make sure you're not callingrepaint()withinpaintevent()example.
the instrumentation example below uses raii , easy apply. alternatively, can use profiler.
#include <qelapsedtimer> #define instrument() instrument instr__ument(__function__) #define instrumentlim(lim) instrument instr__ument(__function__, (lim)) class instrument { qelapsedtimer timer; int limit; const char * function; public: instrument(const char * name, int timelimitms = 20) : function(name), limit(timelimitms) { timer.start(); } ~instrument() { if (timer.elapsed() > limit) { qdebug("%s slow, took %d ms", function, timer.elapsed()); } } } void slot(...) { instrument(); ... } void additem() { instrument(); delete webviewwidget; // delete block ui? mlistwidget = new scrollwidget(); mscrollarea = new scrollarea(this); for(int i=0; i<datalen; i++) { mlistwidget->addsubitem(itemwidget); } }
Comments
Post a Comment