Sunday, July 6th 2008, 4:31pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, February 15th 2008, 10:30am

modal QDialog cpu usage 99%

Hi,

I paint current time in every second in background .

when user press keys just excute modal dialog , but my cpu usage grow up more and more
.
While just paint current time in every second , the modal dialog box seems to use %99 of a CPU. Does any one know why?

The class is below and code is attached:

ScreenWidget -> main background image drawing widget
TimeWidget -> current time display widget per one second(for stress call 0.3 sec)
MsgHandler -> main message handler , this class call modal dialog
SkinDialog -> model dialog
PannelThread -> key event emulator

my env is qt4.1.4 and arm-linux-gcc

FLOW is blow

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
int main(int argc, char* argv[])
{
	QApplication app( argc, argv );
	ScreenWidget mainwin( NULL );
	g_pScreen = &mainwin;
	mainwin.show();
	g_pMsgHandler = new MsgHandler(&mainwin);
	PannelThreadCreate();

	/*
	SkinDialog *pSkinDlg = new SkinDialog(&mainwin);
	pSkinDlg->exec();
	*/
	app.exec();
}

############################################
void* PannelThread(void* arg)
{
	int cnt = 0;

	while(1){
		sleep(1);
		cnt++;
		printf("pannelthread\n");
		if(cnt == 10){
			QEvent *pEvent = new QEvent( (QEvent::Type)5001);
			QApplication::postEvent(g_pScreen, pEvent);
			break;
		}

	}
}

############################################
void ScreenWidget::customEvent(QEvent *pEvent)
{
	QEvent *pEv = new QEvent( (QEvent::Type)5001);
	QApplication::postEvent(g_pMsgHandler, pEv);
}



############################################
void MsgHandler::customEvent(QEvent *pEvent)
{
	OnSetupMenu();
}


void MsgHandler::OnSetupMenu()
{
	SkinDialog *pSkinDlg = new SkinDialog(NULL);
	pSkinDlg->exec();
}


############################################

CTimeWidget::CTimeWidget( QWidget* parent, Qt::WFlags f  )
: QWidget( parent, f | Qt::FramelessWindowHint)
{

	QFont font = QApplication::font();
	font.setPixelSize( 20 );
	font.setBold( true );
	setFont( font );

	setFixedSize( QSize( SIZE_OF_WIDTH, SIZE_OF_HEIGHT ) );
	setAttribute( Qt::WA_OpaquePaintEvent );

	QSize sizeParent = parent->size();
	QSize sizeThis = size();
	QSize size = sizeParent- sizeThis;
	size /= 2;

	QRect rect = parent->rect();
	move( size.rwidth(), rect.top() + 30 );

	QTimer *pTimer = new QTimer(this);
	connect(pTimer, SIGNAL(timeout()), this, SLOT(update()) ); 
	pTimer->start(300);
	//m_nEveryID = startTimer( 1000 );
	m_CurrentTime = QDateTime::currentDateTime();

}
void CTimeWidget::paintEvent(QPaintEvent *pEvent)	
{
//qDebug("[%s:%s]\n", __FILE__, __func__);
	QPainter paint( this );
	QString strTemp;
	QDateTime dateTime;

	QRect rect = pEvent->rect();

	paint.fillRect( rect, QBrush( QColor( 0, 0, 0 ) ) );
	//paint.fillRect( rect, QBrush( QColor( 255, 255, 255 ) ) );
	m_CurrentTime = QDateTime::currentDateTime();	
	dateTime = m_CurrentTime;
	strTemp = dateTime.toString() ;

	DrawTextOutline( paint, strTemp, rect, Qt::AlignLeft | Qt::AlignVCenter );
}
kisungcho has attached the following file:
  • gui_test.zip (20.11 kB - 21 times downloaded - Last download: Jun 27th 2008, 6:09pm)

This post has been edited 1 times, last edit by "kisungcho" (Feb 15th 2008, 10:38am)

  • Go to the top of the page

Rate this thread