Results 1 to 8 of 8

Thread: insert Item to my QTreeWidget

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default insert Item to my QTreeWidget

    Hi everybody,

    QT: 4.1.1

    I am trying to insert Items on my QTreeWidget, i used the QT3 Filosofy, but something its wrong.Can somebody see what?

    Qt Code:
    1. QStringList sprache;
    2. QSqlQuery select (" select id, sprache from sprache_tbl order by sprache desc");
    3. while(select.next())
    4. {
    5. QStringList id = select.value(0).toStringList();
    6. QStringList sprache = select.value(1).toStringList();
    7.  
    8. }
    9. new QTreeWidgetItem(ui.treeWidget, id, sprache );
    To copy to clipboard, switch view to plain text mode 

    Error:
    Qt Code:
    1. test.cpp:56: error: no matching function for call to `QTreeWidgetItem::QTreeWidg
    2. etItem(QTreeWidget*&, QStringList&, QStringList&)'
    3. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:55: note: c
    4. andidates are: QTreeWidgetItem::QTreeWidgetItem(const QTreeWidgetItem&)
    5. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:54: note:
    6. QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, QTreeWidgetIte
    7. m*, int)
    8. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:53: note:
    9. QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, const QStringL
    10. ist&, int)
    11. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:52: note:
    12. QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, int)
    13. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:51: note:
    14. QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, QTreeWidgetItem*,
    15. int)
    16. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:50: note:
    17. QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, const QStringList&
    18. , int)
    19. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:49: note:
    20. QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, int)
    21. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:48: note:
    22. QTreeWidgetItem::QTreeWidgetItem(const QStringList&, int)
    23. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:47: note:
    24. QTreeWidgetItem::QTreeWidgetItem(int)
    25. test.cpp:80:4: warning: no newline at end of file
    26. mingw32-make[1]: *** [release\test.o] Error 1
    27. mingw32-make[1]: Leaving directory `H:/raphael/qt4/mainwindow'
    28. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: insert Item to my QTreeWidget

    maiby it help
    Qt Code:
    1. while(select.next())
    2. {
    3. int id = select.value(0).toInt();
    4. QStringList sprache = select.value(1).toStringList();
    5. }
    6. new QTreeWidgetItem(ui.treeWidget, id, sprache );
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: insert Item to my QTreeWidget

    Hi!
    It didnt helps

    Qt Code:
    1. void MainWindow::selectSprache()
    2. {
    3. int id;
    4. QStringList sprache;
    5. QSqlQuery select (" select id, sprache from sprache_tbl order by sprache desc");
    6. while(select.next())
    7. {
    8. id = select.value(0).toInt();
    9. sprache = select.value(1).toStringList();
    10. }
    11. new QTreeWidgetItem(ui.treeWidget, id, sprache );
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    Error:
    Qt Code:
    1. test.cpp:55: error: no matching function for call to `QTreeWidgetItem::QTreeWidg
    2. etItem(QTreeWidget*&, int&, QStringList&)'
    3. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:55: note: c
    4. andidates are: QTreeWidgetItem::QTreeWidgetItem(const QTreeWidgetItem&)
    5. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:54: note:
    6. QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, QTreeWidgetIte
    7. m*, int)
    8. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:53: note:
    9. QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, const QStringL
    10. ist&, int)
    11. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:52: note:
    12. QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, int)
    13. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:51: note:
    14. QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, QTreeWidgetItem*,
    15. int)
    16. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:50: note:
    17. QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, const QStringList&
    18. , int)
    19. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:49: note:
    20. QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, int)
    21. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:48: note:
    22. QTreeWidgetItem::QTreeWidgetItem(const QStringList&, int)
    23. D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:47: note:
    24. QTreeWidgetItem::QTreeWidgetItem(int)
    25. test.cpp:79:4: warning: no newline at end of file
    26. mingw32-make[1]: *** [release\test.o] Error 1
    27. mingw32-make[1]: Leaving directory `H:/raphael/qt4/mainwindow'
    28. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: insert Item to my QTreeWidget

    sorry

    Qt Code:
    1. new QTreeWidgetItem(ui.treeWidget, sprache, id );
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: insert Item to my QTreeWidget

    What is the relation between id and sprache and how would you like to present that information in your tree?
    QTreeWidgetItem represents a row in a tree and constructing an tree item by passing a string list practically constructs a row with as many columns as items in the string list and passing 2 string lists neither makes sense or is possible.

    Is your intention maybe to show a list with 2 columns, id and sprache, respectively?
    If so, then you should iterate through the string lists and construct QTreeWidgetItems with one row from 'id' list and another row from 'sprache' list...

  6. #6
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: insert Item to my QTreeWidget

    Hi everyboy,

    ZLATKO: Thanks it works, but i thing i have choosen the false Class to present my values from the Database.

    JPN: In QT3 i have use QListView for that and it works perfect.Wath about when i use Q3ListView?I havent use it because i was not able to set Columns in the Designer..But i think it should be easy to ..setColumn..by coding. If it possible i would like to design everything and just implement my functions after..and if i have to change something i would make that by the designer

    Both: What should i do to show in a easy way my results from the database?
    Think DigitalGasoline

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: insert Item to my QTreeWidget

    One very simple way to show contents of a database table:
    http://doc.trolltech.com/4.1/qsqlque...l.html#details

    Just remove the columns you don't want to show and possibly in your case hide the vertical header and that's about it =)
    Last edited by jpn; 28th February 2006 at 15:09.

  8. #8
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: insert Item to my QTreeWidget

    Hi, very interesting!
    I tryied QSQLGqueryModel and it works perfect (Read only)
    Qt Code:
    1. void MainWindow::selectSprache()
    2. {
    3. model->setQuery("SELECT sprache_id, sprache from sprache_tbl");
    4. model->setHeaderData(0, Qt::Horizontal, tr("Id"));
    5. model->setHeaderData(1, Qt::Horizontal, tr("Sprache"));
    6.  
    7.  
    8. ui.tableView->setModel(model);
    9. ui.tableView->show();
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    Read and Write..
    I changed a value and close my app the value will not updated. Why?
    Qt Code:
    1. model->setTable("sprache_tbl");
    2. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    3. model->select();
    4. model->setHeaderData(0, Qt::Horizontal, tr("id"));
    5. model->setHeaderData(1, Qt::Horizontal, tr("sprache"));
    6.  
    7. ui.tableView->setModel(model);
    8. ui.tableView->show();
    To copy to clipboard, switch view to plain text mode 

    Very interesting!I like it
    Last edited by raphaelf; 28th February 2006 at 15:59.
    Think DigitalGasoline

Similar Threads

  1. How to know wich item is clicked QTreeWidget
    By ^NyAw^ in forum Qt Programming
    Replies: 13
    Last Post: 6th November 2007, 23:47
  2. QTreeWidget select item
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2007, 14:26
  3. Inserting Item to a QTreeWidget from Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2007, 11:23
  4. QTreeWidget item editing: want column specificity
    By McKee in forum Qt Programming
    Replies: 12
    Last Post: 10th December 2006, 22:12
  5. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20

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.