PDA

View Full Version : Gui Painting in Thread?



vishal.chauhan
24th July 2007, 06:06
Hi All,

I m using Qt 4.1.5 on my MAC.

I have a thread in which I m doing somework and also emit signal to add Item in a QTreeWidget.

My problem is that Item is shown after I click on the treeWidget but I want them to be seen as they added on the treeWidget.


If some one knows the Issue then plz help me.

Thanks.

marcel
24th July 2007, 06:59
Looks like the widgets doesn't get updated...

Could you post the ode for the slot that updates the tree widget? And also some code from the thread would be useful.

Regards

vishal.chauhan
24th July 2007, 08:00
Actually Main thread class emit signal for update the treeWidget in Gui class...
some part of code....
emit UpdateTree(); in thread class

connect(guiClass,SIGNAL(UpdateTree()),this,SLOT(Sh owTree())); ///in Gui class

void GuiClass::ShowTree()
{
for(int i = 0;i<count;i++)
{
QTreeWidgetItem *pItem = new QTreeWidgetItem(/*Gui TreeWidget */);
pItem->setText(0,"thread");
}
}

that is ok but problem is that whenver new-new treeWidgetItem is created ,,,it is not showing one by one ....whenever i click on treeWidget then it is showing all item at a time.
I want to show treeItem one by one using thread....sometimes it is not showing properly...
whenever i activated the treeWidget then it shows all the created TreeItem....

marcel
24th July 2007, 08:29
connect(guiClass,SIGNAL(UpdateTree()),this,SLOT(Sh owTree())); ///in Gui class


I don't think I understand...
You have a slot in that is executed in a worker thread that updates a widget?

I was thinking that the worker thread emits the signal and the GUI thread updates the interface accordingly.
If this is the case then the slot is executed asynchronously, which might cause a delay before the moment the signal is emitted and the moment the slot gets executed.

You could try updating the tree widget every time you add a new item to it.
How do you exactly add the item to the tree widget?

Regards

vishal.chauhan
24th July 2007, 09:24
Actually I emit a SIGNAL from the Thread and then receive it in the GUI class and add the Item to the treeWidget Like..



QTreeWidgetItem *item = new QTreeWidgetItem(myTreeWidget);

item->setText(0,some String Coming from theThread);
item->setText(0, other string from theThread);

item->setIcon (0, Icon );



This is a slot in which the string I set in TreeWidgetItem is coming from the Thread class which is stored in the LinkList and when a Item is added to the List in the Thread I emit the signal and update the treeWidget as above.