Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sqlite problem.
Forum Updated to NodeBB v4.3 + New Features

Sqlite problem.

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    topocc
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          topocc
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          • T Offline
            T Offline
            topocc
            wrote on last edited by
            #5

            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]

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andreyc
              wrote on last edited by
              #6

              [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.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                topocc
                wrote on last edited by
                #7

                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]

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andreyc
                  wrote on last edited by
                  #8

                  [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.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

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

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      topocc
                      wrote on last edited by
                      #10

                      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]

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        topocc
                        wrote on last edited by
                        #11

                        example de bug report to https://bugreports.qt-project.org/browse/QTBUG-39424

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved