#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); lineCognome = this->findChild("lineCognome"); lineNome = this->findChild("lineCognome"); tableSoci = this->findChild("tableSoci"); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_buttonCerca_clicked() { query.prepare("SELECT id, nome, cognome FROM socio WHERE cognome LIKE :cognome"); query.bindValue( ":cognome", QString("%%1%").arg(lineCognome->text()) ); if ( ! query.exec() ) { qDebug() << query.lastQuery(); return; } //if ( query.size() == 0) { setStatus(Ui::INFO, "no results found"); return; } if (sociModel != nullptr) delete sociModel; // TODO -- does this look a cunning thing? sociModel = new SociModel(nullptr, query); //setStatus(Ui::INFO, QString("%1 results found").arg(query.size())); tableSoci->setModel(sociModel); /* the signal is automagically added by some obscure qt build system, provided the function is named in a standard way */ //QObject::connect(tableSoci, SIGNAL(clicked(const QModelIndex&)), this, SLOT(on_tableSoci_clicked(const QModelIndex&))); tableSoci->show(); } void MainWindow::on_buttonNuovo_clicked() { /* TODO -- please implement me thanks */;} void MainWindow::on_tableSoci_clicked(const QModelIndex& index) { if (index.isValid()) { int id = index.data().toInt(); /* retrieve id socio */ if (id != 0) { /* if click is not on other fields than id... */ EditWindow* w = new EditWindow(id, this); w->show(); // TODO -- free() this window at the end... maybe you can use a self Signal/Slot? } } }