PDA

View Full Version : insert Item to my QTreeWidget



raphaelf
28th February 2006, 15:24
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?



QStringList id;
QStringList sprache;
QSqlQuery select (" select id, sprache from sprache_tbl order by sprache desc");
while(select.next())
{
QStringList id = select.value(0).toStringList();
QStringList sprache = select.value(1).toStringList();

}
new QTreeWidgetItem(ui.treeWidget, id, sprache );


Error:


test.cpp:56: error: no matching function for call to `QTreeWidgetItem::QTreeWidg
etItem(QTreeWidget*&, QStringList&, QStringList&)'
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:55: note: c
andidates are: QTreeWidgetItem::QTreeWidgetItem(const QTreeWidgetItem&)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:54: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, QTreeWidgetIte
m*, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:53: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, const QStringL
ist&, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:52: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:51: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, QTreeWidgetItem*,
int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:50: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, const QStringList&
, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:49: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:48: note:
QTreeWidgetItem::QTreeWidgetItem(const QStringList&, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:47: note:
QTreeWidgetItem::QTreeWidgetItem(int)
test.cpp:80:4: warning: no newline at end of file
mingw32-make[1]: *** [release\test.o] Error 1
mingw32-make[1]: Leaving directory `H:/raphael/qt4/mainwindow'
mingw32-make: *** [release] Error 2

zlatko
28th February 2006, 15:30
maiby it help


while(select.next())
{
int id = select.value(0).toInt();
QStringList sprache = select.value(1).toStringList();
}
new QTreeWidgetItem(ui.treeWidget, id, sprache );

raphaelf
28th February 2006, 15:40
Hi!
It didnt helps :(



void MainWindow::selectSprache()
{
int id;
QStringList sprache;
QSqlQuery select (" select id, sprache from sprache_tbl order by sprache desc");
while(select.next())
{
id = select.value(0).toInt();
sprache = select.value(1).toStringList();
}
new QTreeWidgetItem(ui.treeWidget, id, sprache );

}


Error:


test.cpp:55: error: no matching function for call to `QTreeWidgetItem::QTreeWidg
etItem(QTreeWidget*&, int&, QStringList&)'
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:55: note: c
andidates are: QTreeWidgetItem::QTreeWidgetItem(const QTreeWidgetItem&)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:54: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, QTreeWidgetIte
m*, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:53: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, const QStringL
ist&, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:52: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem*, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:51: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, QTreeWidgetItem*,
int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:50: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, const QStringList&
, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:49: note:
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget*, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:48: note:
QTreeWidgetItem::QTreeWidgetItem(const QStringList&, int)
D:/apps/Qt/4.1.1/include/QtGui/../../src/gui/itemviews/qtreewidget.h:47: note:
QTreeWidgetItem::QTreeWidgetItem(int)
test.cpp:79:4: warning: no newline at end of file
mingw32-make[1]: *** [release\test.o] Error 1
mingw32-make[1]: Leaving directory `H:/raphael/qt4/mainwindow'
mingw32-make: *** [release] Error 2

zlatko
28th February 2006, 15:46
sorry



new QTreeWidgetItem(ui.treeWidget, sprache, id );

jpn
28th February 2006, 15:50
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...

raphaelf
28th February 2006, 16:01
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?

jpn
28th February 2006, 16:04
One very simple way to show contents of a database table:
http://doc.trolltech.com/4.1/qsqlquerymodel.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 =)

raphaelf
28th February 2006, 16:42
Hi, very interesting!
I tryied QSQLGqueryModel and it works perfect (Read only)


void MainWindow::selectSprache()
{
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT sprache_id, sprache from sprache_tbl");
model->setHeaderData(0, Qt::Horizontal, tr("Id"));
model->setHeaderData(1, Qt::Horizontal, tr("Sprache"));


ui.tableView->setModel(model);
ui.tableView->show();

}

Read and Write..
I changed a value and close my app the value will not updated. Why?

QSqlTableModel *model = new QSqlTableModel;
model->setTable("sprache_tbl");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("id"));
model->setHeaderData(1, Qt::Horizontal, tr("sprache"));

ui.tableView->setModel(model);
ui.tableView->show();


Very interesting!I like it