PDA

View Full Version : View update problem



prakash
15th March 2006, 12:39
Hi all,

I have a strange problem, please see the image attached.

I am using QTreeWidget in all the tabs as shown in the image and my app is multithreaded which constantly updates(adds QTreeWidedItem)in first tab cantaining QTreeWidget . If i does not change the tab all is fine but, if change the tab and come to first tab the update from the thread goes to the column header as shown in the image and strange thing is it does not happen every time i run the appication. I coun'd figure why this is happening, any suggestion ?

Thanks in advance.:(

jacek
15th March 2006, 13:00
How does you thread update that widget?


From Qt docs (http://doc.trolltech.com/4.1/threads.html):
The child of a QObject must always be created in the thread where the parent was created. This implies, among other things, that you should never pass the QThread object (this) as the parent of an object created in the thread (since the QThread object itself was created in another thread).
You must ensure that all objects created in a thread are deleted before you delete the QThread. This can be done easily by creating the objects on the stack in your run() implementation.
Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. As noted earlier, QCoreApplication::exec() must also be called from that thread.

prakash
16th March 2006, 04:15
I am using slot to update the view(QTreewidget). All threads sends signals to slot that updates the view. Since slot callback are processed by main thread, i think it is not the thread problem. Any idea ?

Thanks.

jacek
16th March 2006, 13:09
I am using slot to update the view(QTreewidget).
Do you send only data or QTreeWidgetItems?


All threads sends signals to slot that updates the view.
Do you use queued connections? Does your QThread subclass emit signals?

prakash
17th March 2006, 09:58
Yes my QThread subclass emit signals. When i use widget with setItemWidget() it happens but works fine if i do not use cell widget item.

QTreeWidgetItem *item = new QTreeWidgetItem(_pView);
//this works
item->setText(0,url);
item->setTextColor(0,QColor(Qt::blue) );
//but this causes the problem.
QLabel * widget = new QLabel(url,_pView);
widget->setCursor(Qt::PointingHandCursor);
_pView->setItemWidget(item,0, url);

Thanks.:D

jpn
17th March 2006, 10:03
_pView->setItemWidget(item,0, url);

Should this be?

_pView->setItemWidget(item,0, widget);

jacek
17th March 2006, 10:13
Yes my QThread subclass emit signals.
Make sure to add Qt::QueuedConnection all your connections you make with that class.