After creating new project everything now work
Thanks,
This code working :
connector.h
#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <QSqlDatabase>
#include <QMessageBox>
bool createConnection()
{
{
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("test");
db.setPassword("test");
if (!db.open())
{
m.setText("error I");
m.exec();
return false;
}
else
{
return true;
}
}
else
{
m.setText("error II");
m.exec();
return false;
}
}
#endif // CONNECTOR_H
#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <QSqlDatabase>
#include <QMessageBox>
bool createConnection()
{
if (QSqlDatabase::isDriverAvailable("QMYSQL"))
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("test");
db.setPassword("test");
if (!db.open())
{
QMessageBox m;
m.setText("error I");
m.exec();
return false;
}
else
{
return true;
}
}
else
{
QMessageBox m;
m.setText("error II");
m.exec();
return false;
}
}
#endif // CONNECTOR_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "connector.h"
int main(int argc, char *argv[])
{
if (!createConnection())
return 1;
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "connector.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
if (!createConnection())
return 1;
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
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"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
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
baza.pro
# -------------------------------------------------
# Project created by QtCreator 2010-07-26T09:33:19
# -------------------------------------------------
QT += network \
opengl \
sql \
script \
scripttools \
svg \
webkit \
testlib \
dbus
TARGET = baza
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h \
connector.h
FORMS += mainwindow.ui
# -------------------------------------------------
# Project created by QtCreator 2010-07-26T09:33:19
# -------------------------------------------------
QT += network \
opengl \
sql \
script \
scripttools \
svg \
webkit \
testlib \
dbus
TARGET = baza
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h \
connector.h
FORMS += mainwindow.ui
To copy to clipboard, switch view to plain text mode
Bookmarks