Results 1 to 2 of 2

Thread: How to save the content of a QTreeWidget line by line?

  1. #1
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy How to save the content of a QTreeWidget line by line?

    Hi guys,

    I can't find a simple solution just now while changing some source from QTableWidget to QTreeWidget:

    Using QTableWidget I can do something like this:

    Qt Code:
    1. for ( int i = 0; i < tableWidgetPositionen->rowCount(); ++i )
    2. {
    3. query.bindValue ( ":Menge", tableWidgetPositionen->item( i, 0 )->text() );
    4. query.bindValue ( ":Preis", >tableWidgetPositionen->item( i, 1 )->text() );
    5.  
    6. query.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    How can I do something similar using a QTreeWidget?

    I'm sure, it's very simple but I can't figure it out.

    May be I should take a break ...

    Best regards and thanks in advance.

    Guenther
    Davao City, Philippines, Planet Earth, 28.0 °C

  2. #2
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to save the content of a QTreeWidget line by line?

    Ok guys,

    after taking a nap I found this solution:

    Qt Code:
    1. treeWidgetPositionen->setCurrentItem( treeWidgetPositionen->topLevelItem( 0 ) );
    2.  
    3. for ( int i = 0; i < treeWidgetPositionen->topLevelItemCount(); i++ )
    4. {
    5. treeWidgetPositionen->setCurrentItem( treeWidgetPositionen->topLevelItem( i );
    6.  
    7. query.bindValue ( ":Menge", treeWidgetPositionen->topLevelItem( i )->text( 1 ) );
    8. query.bindValue ( ":Preis", treeWidgetPositionen->topLevelItem( i )->text( 2 ) );
    9.  
    10. query.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Is this ok or is there a better way?

    Thanks and have a nice day.

Similar Threads

  1. Why is my application's CPU usage always > 50%
    By richardander in forum Qt Programming
    Replies: 10
    Last Post: 14th October 2010, 22:22
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.