Qt QMYSQL create table problem

Hi there!!!
I have created simple Qt program which needs to connect to the MySql database and create one simple table. It looks like this:

#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QSqlDatabase>
#include <QSqlQuery>

Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QmlApplicationViewer viewer;

QSqlDatabase konekcija= QSqlDatabase::addDatabase("QMYSQL", "kon");
QSqlQuery query(konekcija);

konekcija.setHostName("my_hosting.com");
konekcija.setDatabaseName("my_base_name");
konekcija.setUserName("my_user_name");
konekcija.setPassword("my_pass_word");
konekcija.open();
query.exec("CREATE TABLE experimental_table (id INT NOT NULL, username VARCHAR(20) NOT NULL)");
konekcija.close();

}

When I compile this, it doesn't do anything! Not even to show an empty window!!!
But, when i Run this for second time, it displays a message:
query.exec() database not open

BTW, I have inserted
QT +=core
and also
QT +=sql
into my .pro file!!! So, that's not a problem!!!

I also tried something like:
QSqlQuery query;
with
query.exec("CREATE TABLE experimental_table (id INT NOT NULL, username VARCHAR(20) NOT NULL)", konekcija);
Whatever I do it's always the same!!!
What am I doing wrong? Tanx!!!
Last edited on
Topic archived. No new replies allowed.