Sqlite problem.



  • turns out I'm using sqlite in linux everything works me fine, but when I compiled in windows compiles fine, but when I ran the program I get this.

    well I have a dll from there as executor and I get this error.
    QSqlQuery :: exec: database not open

    the same code works fine in linux, but not windows.

    @
    connetion.h

    bool createConnection()
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("hello.db");
    if (!db.open()){
    QMessageBox::critical(0, QObject::tr("Database Error"),
    db.lastError().text());
    return false;
    }
    return true;
    }

    main.cpp

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    if (!createConnection())
    return 1;

    return app.exec();
    

    }

    I have in my dll:

    QSqlQuery *query = new QSqlQuery;
    query->exec("SELECT * FROM t1 WHERE year >= 1998");
    while (query.next()) {
    QString datas = query.value(0).toString();
    }

    erro QSqlQuery::exec: database not open
    @

    everything works in linux, and windows does not work.


  • Lifetime Qt Champion

    Hi,

    What does db.lastError().text() return ?



  • I guess that default QSqlDatabase is not set when your dll is creating QSqlQuery.

    Can you just pass the QSqlDatabase in the dll or call createConnection() inside dll.



  • database connects fine, just when I want to access the dll does not work

    [quote author="SGaist" date="1401228636"]Hi,

    What does db.lastError().text() return ?[/quote]



  • but linux works well, because that windows will not work, this using qt5.3 in windows and linux
    [quote author="andreyc" date="1401229058"]I guess that default QSqlDatabase is not set when your dll is creating QSqlQuery.

    Can you just pass the QSqlDatabase in the dll or call createConnection() inside dll.[/quote]



  • [quote author="topocc" date="1401238999"]but linux works well, because that windows will not work, this using qt5.3 in windows and linux[/quote]
    You are using share objects (DLLs) if I'm not mistaken.
    Linux and Windows have different memory allocation policies for the shared objects.
    I don't have Windows box, so it is just my theory, that the difference is the reason for the error that you have on Windows.
    To check this theory try to put database open and query in a single executable file.



  • But windows works versión qt5.2
    [quote author="andreyc" date="1401242191"][quote author="topocc" date="1401238999"]but linux works well, because that windows will not work, this using qt5.3 in windows and linux[/quote]
    You are using share objects (DLLs) if I'm not mistaken.
    Linux and Windows have different memory allocation policies for the shared objects.
    I don't have Windows box, so it is just my theory, that the difference is the reason for the error that you have on Windows.
    To check this theory try to put database open and query in a single executable file.
    [/quote]



  • [quote author="topocc" date="1401242735"]But windows works versión qt5.2[/quote]
    Well, if your source code is the same for both versions of Qt and one version doesn't work then it is possible that you have discovered a bug (regression) in Qt.
    I would suggest to create a minimal repro example and submit a bug report.

    "Here":http://qt-project.org/wiki/ReportingBugsInQt is how to report the bugs in Qt.


  • Lifetime Qt Champion

    Where are you running this program when you get the error ? Through Qt Creator ?



  • Hi, I run it through qtcreator, also does not work if qmake and make compile it. It does not work.

    [quote author="SGaist" date="1401268728"]Where are you running this program when you get the error ? Through Qt Creator ?[/quote]




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.