pro:
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Game
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
mainwindow.cpp:
#include "QtSql"
#include "QSqlDatabase"
//#include "QtDebug"
//#include "QFileInfo"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
mydb = new QSqlDatabase::addDatabase("QSQLITE"); <------- ERROR LINE
mydb->setDatabaseName("C:/sqllite2/bazadannyh.sqlite");
bool ok = mydb->open();
widget = new QWidget();
mainwindow.h:
#include <QSqlDatabase>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QString *s;
QSqlDatabase *mydb;
I declared mydb here, because otherwise i can't get access to it in my public slots. Is it OK?
main.cpp:
#include "mainwindow.h"
#include <QApplication>
#include "QtGui"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Is the place i choose to declare DB is correct? Or should i change it?
ERROR: mainwindow.cpp:19: error: expected type-specifier mydb = new QSqlDatabase::addDatabase("QSQLITE"); expected ';'
Help me! What should i do?