I have the following code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSql>
#include <QDebug>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
m.setDatabaseName(":baza:");
bool ok = m.open();
if (ok)
{
qDebug() << "connected" << endl;
}
else
{
qDebug() << "not Connected " << endl;
qDebug() << m.lastError();
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSql>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase m = QSqlDatabase::addDatabase("QSQLITE");
m.setDatabaseName(":baza:");
bool ok = m.open();
if (ok)
{
qDebug() << "connected" << endl;
}
else
{
qDebug() << "not Connected " << endl;
qDebug() << QSqlDatabase::drivers() << endl;
qDebug() << m.lastError();
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
and it's returning:
not Connected
("QSQLITE", "QODBC3", "QODBC")
QSqlError(-1,
"Error opening database",
"unable to open database file")
not Connected
("QSQLITE", "QODBC3", "QODBC")
QSqlError(-1, "Error opening database", "unable to open database file")
To copy to clipboard, switch view to plain text mode
What's wrong?
Bookmarks