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. Can't connect to qsqlite plugin
QtWS25 Last Chance

Can't connect to qsqlite plugin

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.3k Views
  • 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.
  • K Offline
    K Offline
    korwru
    wrote on last edited by
    #1

    On OS with installed QT - everything works. But if QT not installed - i see some bugs...

    Programm can't view plugins and crashed with runtime error if the creation of the base is in a separate class CDatabase. If the content CDatabase :: CDatabase i moved to MainWindow :: MainWindow - everything works. Any ideas?

    OS: Windows XP / Windows 7 x64
    Full source code (failed on OS without QT): http://pastebin.com/6Q2Jtn57
    Full source code (working on all OS): http://pastebin.com/C8KfZ1NB

    mainwindow.cpp
    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "cdatabase.h"

    CDatabase db;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    cdatabase.h
    @
    #ifndef CDATABASE_H
    #define CDATABASE_H

    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlError>
    #include <QString>

    class CDatabase
    {
    public:
    CDatabase();
    private:
    QSqlDatabase db;
    };

    #endif // CDATABASE_H
    @

    cdatabase.cpp
    @
    #include "cdatabase.h"

    CDatabase::CDatabase()
    {
    QString connection = QString(QSqlDatabase::defaultConnection);
    if (QSqlDatabase::contains(connection)) {
    db = QSqlDatabase::database(connection);
    } else {
    db = QSqlDatabase::addDatabase("QSQLITE", connection);
    db.setDatabaseName("db.sqlite");
    db.open();
    }
    }
    @

    main.cpp, mainwindow.h, wolqru.pro - not important. For source code see link above.

    List of files in program dir:
    platforms\qwindows.dll
    platforms\qminimal.dll
    sqldrivers\qsqlite.dll
    wolqru.exe
    Qt5Core.dll
    libgcc_s_sjlj-1.dll
    libstdc++-6.dll
    libwinpthread-1.dll
    Qt5Widgets.dll
    Qt5Sql.dll
    Qt5Gui.dll
    libGLESv2.dll
    libEGL.dll
    icuin49.dll
    icuuc49.dll
    icudt49.dll
    D3DCompiler_43.dll

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

      Hi,

      To setup the database you have make an instance of your CDatabase class somewhere (i.e. main.cpp). Just having this class compiled in you executable won't do anything if not used somewhere.

      Hope it helps

      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
      • K Offline
        K Offline
        korwru
        wrote on last edited by
        #3

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

        To setup the database you have make an instance of your CDatabase class somewhere (i.e. main.cpp). [/quote]

        I connect to class in mainwindow.cpp by #include "cdatabase.h". And try to create a new object "CDatabase db;" . May by i something do not understand?

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

          Sorry, i think i've misunderstood what you wrote.

          Could you show the version of the code that is working ?

          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
          • K Offline
            K Offline
            korwru
            wrote on last edited by
            #5

            [quote author="SGaist" date="1365196087"]Sorry, i think i've misunderstood what you wrote.
            Could you show the version of the code that is working ?[/quote]

            See link above to view full code of all files.

            1. Create a standart QT Gui application with QT Creator.

            change mainwindow.cpp
            @#include "mainwindow.h"
            #include "ui_mainwindow.h"

            #include <QtSql/QSqlDatabase> // i add this
            #include <QtSql/QSqlError> // i add this
            #include <QString> // i add this
            QSqlDatabase db; // i add this

            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
            ui->setupUi(this);

            //I add this START

            QString connection = QString(QSqlDatabase::defaultConnection);
            if (QSqlDatabase::contains(connection)) {
                db = QSqlDatabase::database(connection);
            } else {
                db = QSqlDatabase::addDatabase("QSQLITE", connection);
                db.setDatabaseName("db.sqlite");
                db.open();
            }
            

            //I add this END

            }

            MainWindow::~MainWindow()
            {
            delete ui;
            }
            @

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

              For the plugin bug, IIRC, you have to put all plugins in a "plugins" folder besides your application.
              plugins/platform
              /sqldrivers
              etc...

              About your code, since you're using the default connection, you're overcomplicating things:

              @
              QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
              db.setDatabaseName(""db.sqlite"");
              if (!db.open()) {
              QMessageBox::critical(0, qApp->tr("Cannot open database"),
              qApp->tr("Unable to establish a database connection."));
              }
              @

              There is no need to keep a db object, since all other calls to i.e. QSqlQuery will use the default connection.

              This technique is used i.e. by the sql examples in Qt's sources.

              Hope it helps

              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
              • K Offline
                K Offline
                korwru
                wrote on last edited by
                #7

                [quote author="SGaist" date="1365197882"]
                There is no need to keep a db object, since all other calls to i.e. QSqlQuery will use the default connection.
                [/quote]
                Thank you. I will use this.

                [quote author="SGaist" date="1365197882"]For the plugin bug, IIRC, you have to put all plugins in a "plugins" folder besides your application.
                plugins/platform
                /sqldrivers
                etc...
                [/quote]
                i copy dll's in plugins folder and it doesn't solve my problem (
                plugins\platforms\qwindows.dll; plugins\sqldrivers\qsqlite.dll

                In failure case Process Explorer always!! show path:
                C:\QT\Qt5.0.1\5.0.1\mingw47_32\plugins\sqldrivers\qsqlite.dll
                C:\QT\Qt5.0.1\5.0.1\mingw47_32\plugins\platforms\qwindows.dll

                In working case Process Explorer show correct path:
                \Device\Mup\vboxsrv\CPP\Projects\wolq-test\release\sqldrivers\qsqlite.dll
                \Device\Mup\vboxsrv\CPP\Projects\wolq-test\release\platforms\qwindows.dll

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

                  Have a look at the "deployment documentation":http://qt-project.org/doc/qt-5.0/qtdoc/deployment-windows.html it seems that you are missing some dll's for mingw (also check the plugin directories from there, I think I have mixed something with the Qt4 deployment)

                  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
                  • K Offline
                    K Offline
                    korwru
                    wrote on last edited by
                    #9

                    I think - it's bug... Can you test my apps on Windows with QT5?

                    https://bugreports.qt-project.org/browse/QTBUG-30538 (examples attach there)
                    1 program - failure, 2 program - working.

                    The difference between these programs is very small.

                    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