1 Attachment(s)
How to show connected sqlite database in Tableview
So hello,I have an existing database in my project.I connected my database to my prog.I can't understand how to show my database in Tableview.Please look at my project, what I'm doing wrong?
Attachment 10369
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
mydb.setDatabaseName("C:/GLOSSARIY/Ð¯Ð´ÐµÑ€Ð½Ð°Ñ Ð¼ÐµÐ´Ð¸Ñ†Ð¸Ð½Ð°.sqlite");
mydb.open();
if (!mydb.open())
ui->label->setText("Failed to open your database");
else
ui->label->setText("Connected succesfully...");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
query.exec("SELECT * FROM ГлоÑÑарий по радиобиологии");
model->setQuery(query);
ui->tableView->setModel(model);
}
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSql>
#include <QtDebug>
#include <QFileInfo>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
//public:
//QSqlDatabase mydb;
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
Re: How to show connected sqlite database in Tableview
I think that SQL query is NOT executed (QSqlQuery::exec returns false) because You have spaces in name of table.
It should looks like :
Code:
query.exec("SELECT * FROM \"ГлоÑÑарий по радиобиологии\"");
Re: How to show connected sqlite database in Tableview
Thank you Lesiok!....interesting, how I can stretch the field in the table to see all the word in it, ....I tried use
Code:
ui
->tableView
->horizontalHeader
()->setSectionResizeMode
(QHeaderView::Stretch);
but it does not show all the text!
solved this problem never mind.