PDA

View Full Version : QWidget::update() qeustion



tanki95
13th March 2008, 08:13
Hi,

I have a question about QWidget::update() function.
I was told that when I call update(), paintEvent() will be called automatically.
Yes, it works.

But, sometime, segment fault proglem happens and core contents are following.
What is the problem with calling update()?

Do you have any idea??

Please, help me.


#0 miRegionOp (dest=@0x2a9c35fb70, reg1=Variable "reg1" is not available.
) at ../..include/QtCore../../src/corelib/tools/qrect.h:221
#1 0x0000002a9632c5a7 in UnionRegion (reg1=0x177aa00, reg2=0x2a9cbe6d70, dest=@0x2a9c35fb70) at painting/qregion_unix.cpp:1109
#2 0x0000002a9632c925 in QRegion::unite (this=0xc0b978, r=@0x4b40f500) at painting/qregion_unix.cpp:2678
#3 0x0000002a962feab9 in QRegion::operator+ (this=Variable "this" is not available.
) at painting/qregion.h:78
#4 0x0000002a962feb82 in QRegion::operator+= (this=0xc0b978, r=Variable "r" is not available.
) at painting/qregion.cpp:439
#5 0x0000002a9632dca7 in QWidgetBackingStore::dirtyRegion (this=0xc0b970, rgn=Variable "rgn" is not available.
) at painting/qbackingstore.cpp:499
#6 0x0000002a9632f1c5 in QWidget::update (this=0xbe4d40, rgn=@0x4b40f5e0) at painting/qbackingstore.cpp:904
#7 0x0000002a9632f239 in QWidget::update (this=0xbe4d40, r=Variable "r" is not available.
) at painting/qbackingstore.cpp:888
#8 0x0000002a9632f2c6 in QWidget::update (this=Variable "this" is not available.
) at ../..include/QtGui../../src/gui/kernel/qwidget.h:883
#9 0x000000000046c5b2 in CUIGOCIImgStatus::UpdateValue (this=0xbe4d40, _szImgRef=0x4b410550 "2000-09-13.03-00-00", _iSlotNum=5, _enBand=ENI_GOCI_B6_BAND) at UIGOCIImgStatus.cpp:317

jpn
13th March 2008, 08:20
Are you by any chance using multiple threads in your application?

tanki95
13th March 2008, 17:38
Yes.

Actually many dialogs are updated by threads.

Is there any thing to consider to update GUI for the multiple threads?

Thanks.

wysota
13th March 2008, 18:18
You can't access GUI objects (dialogs included) from within worker threads.

tanki95
13th March 2008, 18:37
I cannot understand I can't access GUIs in worker thread.

CUIGOCIImgStatus is a class which inherits QWidget. It also includes <ui_gociimgstatus.h> generated by qmake.

I updates by using a thread which check status of other system.
If status is changed,
I set values in member variables in CUIGOCIImgStatus to update , then I call updates().
Then paintEvent() is called.
CUIGOCIImgStatus objects is a global variable to share.
It is created by main thread but is updated by only one other threads.

Usually, this works well.

but 1 out of 10, segment fault happens.

anything wrong??

wysota
13th March 2008, 21:05
I cannot understand I can't access GUIs in worker thread.
Well... you just can't.


I updates by using a thread which check status of other system.
If status is changed,
I set values in member variables in CUIGOCIImgStatus to update , then I call updates().
Sorry, that's forbidden.


Usually, this works well.
Yes... usually :) That's the key word here.

tanki95
14th March 2008, 01:27
Ok... I think I understand what you meant.

You mean I should call 'update()' in the main GUI thread?

But how do I call update() in the main GUI thread if the content of the GUI is changed from the other thread?

If I use timer thread by using QTimer, it is also forbidden. right?

Do you have any suggestion for the current my situation??

Thank you very much for your reply.

wysota
14th March 2008, 03:29
You mean I should call 'update()' in the main GUI thread?
Yes, that too.


But how do I call update() in the main GUI thread if the content of the GUI is changed from the other thread?

Use signals and slots or custom events.


If I use timer thread by using QTimer, it is also forbidden. right?
I'm not sure I understand what you mean. You can use timers in other threads.