Advertisement
DBDEBICH

[db error] mainwindow.cpp

Apr 26th, 2024
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | Source Code | 0 0
  1. #include "mainwindow.h"
  2. #include "./ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent)
  5.     : QMainWindow(parent)
  6.     , ui(new Ui::MainWindow)
  7. {
  8.     ui->setupUi(this);
  9.  
  10.     db = QSqlDatabase::addDatabase("QSQLITE");
  11.     db.setDatabaseName("../finances.db");
  12.  
  13.     if (db.isOpen()) {
  14.         model = new QSqlTableModel(this, db);
  15.         model->setTable("Finances");
  16.         model->select();
  17.         ui->tableView->setModel(model);
  18.     } else ui->label->setText("Error: " + QString(db.lastError().databaseText()));
  19. }
  20.  
  21. MainWindow::~MainWindow() { delete ui; }
  22.  
Tags: cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement