I try to create simply application Qt and Mysql
and there I find some unexpected problems.
I make one project on C not C++, and it work, but this is not from QT, simply C code from gedit and gcc
I have one project in QT
one file is
connector.h
#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <QSqlDatabase>
#include <QMessageBox>
bool createConnection()
{
{
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("user");
db.setPassword("pass");
if (!db.open())
{
m.setText("Greska I");
m.exec();
return false;
}
else
{
return true;
}
}
else
{
m.setText("Nema drajver za DB");
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("user");
db.setPassword("pass");
if (!db.open())
{
QMessageBox m;
m.setText("Greska I");
m.exec();
return false;
}
else
{
return true;
}
}
else
{
QMessageBox m;
m.setText("Nema drajver za DB");
m.exec();
return false;
}
}
#endif // CONNECTOR_H
To copy to clipboard, switch view to plain text mode
and 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
and this project not work at QT
Bookmarks