Browse Source

working on Signal/Slot for tableView

fiffty-50 4 years ago
parent
commit
ca2f995d4c
2 changed files with 18 additions and 0 deletions
  1. 15 0
      logbookwidget.cpp
  2. 3 0
      logbookwidget.h

+ 15 - 0
logbookwidget.cpp

@@ -50,6 +50,13 @@ logbookWidget::logbookWidget(QWidget *parent) :
     view->hideColumn(0); // don't show the ID
     view->show();
 
+    //connect(this, ui->tableView->selectionChanged(), this, )
+    connect(
+     ui->tableView->selectionModel(),
+     SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+     SLOT(on_tableView_changed(const QItemSelection &, const QItemSelection &))
+    );
+
     auto stop = std::chrono::high_resolution_clock::now();
     auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
     qDebug() << "logbookWidget: Time taken for lookup and rendering: " << duration.count() << " microseconds";
@@ -138,3 +145,11 @@ void logbookWidget::on_tableView_pressed(const QModelIndex &index)
     SelectedFlight = ui->tableView->model()->data(NewIndex).toInt();
     qDebug() << "Selected Flight with ID#(entered): " << SelectedFlight;
 }
+
+void logbookWidget::on_tableView_changed(const QItemSelection &index, const QItemSelection &index2)// TO DO
+{
+    //auto NewIndex = ui->tableView->model()->index(index.row(), 0);
+    //SelectedFlight = ui->tableView->model()->data(NewIndex).toInt();
+    qDebug() << "Selected Flight with ID#(signalslot): " << SelectedFlight;
+    qDebug() << "lol";// << index.value(1) << index.at(2);
+}

+ 3 - 0
logbookwidget.h

@@ -2,6 +2,7 @@
 #define LOGBOOKWIDGET_H
 
 #include <QWidget>
+#include <QItemSelection>
 
 namespace Ui {
 class logbookWidget;
@@ -30,6 +31,8 @@ private slots:
 
     void on_tableView_pressed(const QModelIndex &index);
 
+    void on_tableView_changed(const QItemSelection &index, const QItemSelection &index2);
+
 private:
     Ui::logbookWidget *ui;
 };