Results 1 to 7 of 7

Thread: Treewidgetitems list

  1. #1
    Join Date
    May 2016
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Post Treewidgetitems list

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Treewidgetitems list

    Looks like you forgot to post the code that processes your SQL query and creates tree widget items.

    Cheers,
    _

  3. #3
    Join Date
    May 2016
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Treewidgetitems list

    Thanks for reply

    here are some code I have used for desplaying data in Treewidget from database.
    Qt Code:
    1. QSqlquery query;
    2. query.prepare("select DeviceName from Devices" );
    3.  
    4. if(query.exec())
    5. {
    6. ui->treeWidget_Device->setColumnCount(1);
    7.  
    8. QList<QTreeWidgetItem *> items;
    9.  
    10. for (int i = 0; i < 10; ++i) // here I have confusion about list numbers. y list is verx big and will be added more
    11.  
    12. item.append(new QTreeWidgetItem((QTreeWidget*)0, QString("item: %1").arg(i))); //this is an example with simple string but I want to show
    13. my query in here
    14. ui->treeWidget_Device->insertTopLevelItems(0, items);
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 
    hope these code will be enough to understand my difficulty...

    looking for your advice..

    Thanks
    Last edited by sam123; 31st May 2016 at 13:05.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Treewidgetitems list

    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,
    _

  5. #5
    Join Date
    May 2016
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Treewidgetitems list

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Treewidgetitems list

    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,
    _

  7. #7
    Join Date
    May 2016
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Treewidgetitems list

    Thank you so much for your guidance...

Similar Threads

  1. Replies: 0
    Last Post: 12th May 2016, 18:59
  2. Replies: 4
    Last Post: 14th June 2012, 23:33
  3. Replies: 1
    Last Post: 21st July 2011, 23:06
  4. Replies: 1
    Last Post: 23rd April 2011, 17:33
  5. List View with sections for alphabetialy sorted list
    By woodtluk in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2010, 11:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.