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()));
connect(ui.tree, SIGNAL(itemClicked (tables,0)), this, SLOT(selectTable()));
init();
}
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();
}
To copy to clipboard, switch view to plain text mode
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();
*/
root
->setIcon
(0,
QIcon(QString::fromUtf8(":/images/images/database.jpg")));
root->setText(0, "inventar");
tables
->setIcon
(0,
QIcon(QString::fromUtf8(":/images/images/table.jpg")));
tables->setText(0, "tabellen");
model->setTable(table);
//So kann man jeder Feld update: OnFiledChange
model->select();
ui.tableView->setModel(model);
ui.tableView->show();
}
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();
}
To copy to clipboard, switch view to plain text mode
void MainWindow::addItemsToTreeWidget()
{
ui.tree->clear();
// ui.tree->header()->setResizeMode(QHeaderView::Stretch);
root
->setIcon
(0,
QIcon(QString::fromUtf8(":/images/images/database.jpg")));
root->setText(0, "inventar");
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);
items->setText(0, tabelle);
items
->setIcon
(0,
QIcon(QString::fromUtf8(":/images/images/table.jpg")));
}
}
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")));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks