PDA

View Full Version : QTreeWidget SIGNAL



raphaelf
5th March 2006, 17:00
QT:4.1.1

Hello everybody,

I am trying to call a function by clicking on a item with the signal: itemClicked()
It happens nothing beim clicking on a item. Can somebody see what is wrong:




MainWindow::MainWindow()

{
ui.setupUi(this);


connect(ui.tabellen_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(selectTable()));
connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(openLoginDialog()));
connect(ui.actionNeu, SIGNAL(triggered()), this, SLOT(insertNewRow()));
connect(ui.abfrage_btn, SIGNAL(clicked()), this, SLOT(selectTable()));
connect(ui.new_btn, SIGNAL(clicked()), this, SLOT(insertNewRow()));
connect(ui.delete_btn, SIGNAL(clicked()), this, SLOT(deleteRow()));
connect(ui.abfrage_btn, SIGNAL(clicked()), this, SLOT(addItemsToTreeWidget()));


QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
QTreeWidgetItem *tables = new QTreeWidgetItem(root);
connect(ui.tree, SIGNAL(itemClicked (tables,0)), this, SLOT(selectTable()));


init();

}





void MainWindow::selectTable()
{
/*
QString table = ui.tabellen_cb->currentText();
QSqlTableModel *model = new QSqlTableModel;
model->setTable(table);
//So kann man jeder Feld update: OnFiledChange
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();


ui.tableView->setModel(model);
ui.tableView->show();
*/
QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
root->setText(0, "inventar");

QTreeWidgetItem *tables = new QTreeWidgetItem(root);
tables->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));
tables->setText(0, "tabellen");
QString table = tables->text(0);
QMessageBox::information(this,"",table);
QSqlTableModel *model = new QSqlTableModel;
model->setTable(table);
//So kann man jeder Feld update: OnFiledChange
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();


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

}




void MainWindow::addItemsToTreeWidget()
{
ui.tree->clear();
ui.tree->setObjectName(QLatin1String("ui.tree"));
ui.tree->setHeaderLabels(QStringList(tr("database")));
// ui.tree->header()->setResizeMode(QHeaderView::Stretch);

QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
root->setText(0, "inventar");

QTreeWidgetItem *tables = new QTreeWidgetItem(root);
tables->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));
tables->setText(0, "tabellen");

QSqlQuery select("select * from sysobjects where xtype = 'U' order by name");
while(select.next())
{
QString tabelle = select.value(0).toString();
//new QTreeWidgetItem(tables, tabelle, 0);
QTreeWidgetItem *items = new QTreeWidgetItem(tables);
items->setText(0, tabelle);
items->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));

}

}

wysota
5th March 2006, 17:18
connect(ui.tree, SIGNAL(itemClicked (tables,0)), this, SLOT(selectTable()))

You can't set values in connect statements. You should use types there.

Try this:

connect(ui.tree, SIGNAL(itemClicked (QTreeWidgetItem*,int)), this, SLOT(selectTable()))

raphaelf
5th March 2006, 18:06
hi wysota!
It works like this:


connect(ui.tree, SIGNAL(itemClicked (QTreeWidgetItem*,int)), this, SLOT(selectTable()))


But i would like to call "selectTable()" just if i click a item of tables (not root and tables it self, but all items of tables should be able to call my function "selectTable()":


.
.
QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
root->setText(0, "inventar");
QTreeWidgetItem *tables = new QTreeWidgetItem(root);
.
.

Thats why i tryed:


connect(ui.tree, SIGNAL(itemClicked (tables,0)), this, SLOT(selectTable()))


Is that complex to implement? :rolleyes:

jpn
5th March 2006, 18:18
You can't use parameter values in SIGNAL macro.
You need to implement a slot for checking which item was clicked and then call selectTable() if appropriate.

wysota
5th March 2006, 18:19
Provide a custom slot which checks values of those parameters.


void someclass::someslot(QTreeWidgetItem *item, int column){
if(item && column==0) selectTable();
}

raphaelf
5th March 2006, 18:30
Hi everybody :rolleyes:
Ok i will do that!
Is there a possibility to get my selected Item text? I found none function at QTreeWidget and QTreeWidgetItem :(
. I found just "text()".
In QT 3 i could use xx->currentText().

Its easy to get my selected text or its not possible?

jpn
5th March 2006, 18:35
ui.tree->currentItem()->text()