qlands
4th May 2012, 14:18
Hi,
I having the said problem in a command line application, however I'm getting the error in Windows (mingw) and not in Linux.
The code in the main is:
#include <QObject>
#include "mydbconn.h"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDir>
#include <QTextStream>
#include <tclap/CmdLine.h>
#include <QtCore/QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
...
mydb = QSqlDatabase::addDatabase("QMYSQL","connection1");
mydb.setHostName(host);
mydb.setPort(port.toInt());
if (!userName.isEmpty())
mydb.setUserName(userName);
if (!password.isEmpty())
mydb.setPassword(password);
mydb.setDatabaseName(dbName);
mydb.open();
// a.exec() Not execute the event loop. All the processes are in the main
}
Any idea how to fix the problem?
Thanks,
Carlos.
Added after 1 7 minutes:
Ups... it gets fixed with
#include <QtCore/QCoreApplication>
QCoreApplication a(argc, argv);
I was running another application that did not have those lines... All works fine now :o
I having the said problem in a command line application, however I'm getting the error in Windows (mingw) and not in Linux.
The code in the main is:
#include <QObject>
#include "mydbconn.h"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDir>
#include <QTextStream>
#include <tclap/CmdLine.h>
#include <QtCore/QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
...
mydb = QSqlDatabase::addDatabase("QMYSQL","connection1");
mydb.setHostName(host);
mydb.setPort(port.toInt());
if (!userName.isEmpty())
mydb.setUserName(userName);
if (!password.isEmpty())
mydb.setPassword(password);
mydb.setDatabaseName(dbName);
mydb.open();
// a.exec() Not execute the event loop. All the processes are in the main
}
Any idea how to fix the problem?
Thanks,
Carlos.
Added after 1 7 minutes:
Ups... it gets fixed with
#include <QtCore/QCoreApplication>
QCoreApplication a(argc, argv);
I was running another application that did not have those lines... All works fine now :o