PDA

View Full Version : Treewidgetitems list



sam123
31st May 2016, 10:17
Hello,

I want to show my product list in QTreeWidget from my sql database. I am trying with QList<QTreeWidgetItems * >items, but still not able to get output.
secondly, I have developed GUI for desplaying my all product details, after clicking on my device name from TreeWidget my all detail data should be shown in my GUI.

looking for your solutions..

Thanks in advance

anda_skoa
31st May 2016, 11:51
Looks like you forgot to post the code that processes your SQL query and creates tree widget items.

Cheers,
_

sam123
31st May 2016, 12:50
Thanks for reply

here are some code I have used for desplaying data in Treewidget from database.


QSqlquery query;
query.prepare("select DeviceName from Devices" );

if(query.exec())
{
ui->treeWidget_Device->setColumnCount(1);

QList<QTreeWidgetItem *> items;

for (int i = 0; i < 10; ++i) // here I have confusion about list numbers. y list is verx big and will be added more

item.append(new QTreeWidgetItem((QTreeWidget*)0, QString("item: %1").arg(i))); //this is an example with simple string but I want to show
my query in here
ui->treeWidget_Device->insertTopLevelItems(0, items);

}

hope these code will be enough to understand my difficulty...

looking for your advice..

Thanks

anda_skoa
31st May 2016, 13:05
You need to iterate over the query, the documentation has an example for that.

Independent of that, do your other tree widget items appear? I.e. the ones with "item: number"?

Cheers,
_

sam123
31st May 2016, 13:13
Yes the one with items :numbers appears in my treewidget, but Its just an example i have given to show my code. I want to display data list from database

for example I have devices list in database table such as,

1. A
2. B
3. C
4. D
.
.
.

I want to display the above list in QTreewidget..

Thanks

anda_skoa
31st May 2016, 13:46
Then you need to iterate over the query instead of over a numerical range.

You can post that code if you don't get it to work.

Not really useful to post code that works but isn't what you are actually doing :)

Cheers,
_

sam123
31st May 2016, 15:11
Thank you so much for your guidance...