Sample Sqlite Database Application



  • Hi,

    Can some point to link for sample database application for Android QT C++ or a sample


    Regards,
    Avtansh Sharma


  • Moderators

    @Avtansh-Sharma
    Here you go
    Simple answer for a simple question.



  • Haha...that was indeed funny.

    I did it already actually for android sqlite drivers needs to loaded. I am looking for that process. This process is not well documented or may be I am not able to find it


    Regards,
    Avtansh Sharma


  • Lifetime Qt Champion

    Hi,

    What exactly is your problem with the SQLite plugin ? It's already available for Android so you have to give more details about the trouble you are encountering.



  • Problem is on the target device i.e Android

    QSqlite drivers are not able to load on the device that is why error is coming

    QSqlError error= m_db.lastError() ;
    qInfo()<<error;
    QSqlError("", "Driver not loaded", "Driver not loaded")

    I have further checked i(QSqlDatabase::drivers().isEmpty()) results as true.


  • Lifetime Qt Champion

    Then you should tell what version of Qt you are using, as well as developing platform, Android version etc.



  • Android OS version is 7.0 Nougat Cyanogen Mod
    Android Architecture is arm
    Host Machine OS -Ubuntu 16.04 lts
    QT creator version 4.3.1
    QT version Based on Qt 5.9.0 (GCC 5.3.1 20160406 (Red Hat 5.3.1-6), 64 bit)
    I have not built this from source code. I ran offline installer


  • Moderators

    @Avtansh-Sharma said in Sample Sqlite Database Application:

    QT version Based on Qt 5.9.0 (GCC 5.3.1 20160406 (Red Hat 5.3.1-6), 64 bit)

    This is from QtCreator "Help/About Qt Creator", right? This only says which Qt version was used to build QtCreator, it is not necessarily the Qt version you're using to build your app.



  • Now this is confusing if it does not show version. Then what i need to get version



  • Anyway is my orignal query a bug.?
    I don't understand why sqlite driver is missing on Android it should be package with apk file automatically.
    If there are any other steps please inform me


  • Moderators

    @Avtansh-Sharma It is not confusing: "About SOMETHING" is always providing information about SOMETHING.
    So, in case of QtCreator it tells you what QtCreator version it is and what Qt version was used to build it.
    QtCreator can handle many different Qt versions at the same time.
    You should know what you installed. If not go to "Tools/Options/Build & Run/Qt Versions" and see there.

    Regarding your issue: you could manually check what is inside the APK. And you can try to set QT_DEBUG_PLUGINS, see http://doc.qt.io/qt-5/debug.html



  • @jsulm I have installed only qt 5.9.0



  • I already set it to 1

    Below is the output

    W libsplinechart.so: (null):0 ((null)): QSqlDatabase: QSQLITE driver not loaded
    W libsplinechart.so: (null):0 ((null)): QSqlDatabase: available drivers:


  • Moderators

    @Avtansh-Sharma There should be something above these two lines saying more about actual issue



  • @jsulm above these lines are only linking and compilation. If you want i can post it but I don't think it would be of use.
    Anyway fyi
    Starting remote process.I art : Late-enabling -Xcheck:jni
    W System : ClassLoader referenced unknown path:
    I QtCore : Start
    W linker : /data/app/org.qtproject.example.splinechart-1/lib/arm/libQt5Gui.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/app/org.qtproject.example.splinechart-1/lib/arm/libQt5Widgets.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/app/org.qtproject.example.splinechart-1/lib/arm/libQt5Charts.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/app/org.qtproject.example.splinechart-1/lib/arm/libQt5AndroidExtras.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/app/org.qtproject.example.splinechart-1/lib/arm/libQt5Bluetooth.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/app/org.qtproject.example.splinechart-1/lib/arm/libQt5Sql.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/platforms/android/libqtforandroid.so: unsupported flags DT_FLAGS_1=0x81
    I Qt : qt start
    I art : Do partial code cache collection, code=10KB, data=27KB
    I art : After code cache collection, code=10KB, data=27KB
    I art : Increasing code cache capacity to 128KB
    W linker : /data/app/org.qtproject.example.splinechart-1/lib/arm/libsplinechart.so: unused DT entry: type 0xf arg 0x73b4
    W : (null):0 ((null)): QSqlDatabase: QSQLITE driver not loaded
    W : (null):0 ((null)): QSqlDatabase: available drivers:
    W : (null):0 ((null)): QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
    D : ../splinechart/devicedata.cpp:55 (DeviceData::DeviceData(QObject*)): Error: connection with database fail
    I Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8974_LA.BF.1.1.3_RB1__release_AU (I741a3d36ca)
    I Adreno-EGL: OpenGL ES Shader Compiler Version: E031.29.00.00
    I Adreno-EGL: Build Date: 04/04/16 Mon
    I Adreno-EGL: Local Branch: mybranch19053788
    I Adreno-EGL: Remote Branch: quic/LA.BF.1.1.3_rb1.12
    I Adreno-EGL: Local Patches: NONE
    I Adreno-EGL: Reconstruct Branch: NOTHING
    I OpenGLRenderer: Initialized EGL, version 1.4
    D OpenGLRenderer: Swap behavior 1
    W Adreno-ES20: <get_gpu_clk:229>: open failed: errno 13
    W : (null):0 ((null)): WARNING: QApplication was not created in the main() thread.
    W libsplinechart.so: (null):0 ((null)): QSqlQuery::exec: database not open
    W libsplinechart.so: (null):0 ((null)): QSqlQuery::exec: database not open
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqgif.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqicns.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqico.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqjpeg.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqtga.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqtiff.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqwbmp.so: unsupported flags DT_FLAGS_1=0x81
    W linker : /data/data/org.qtproject.example.splinechart/qt-reserved-files/plugins/imageformats/libqwebp.so: unsupported flags DT_FLAGS_1=0x81
    W libsplinechart.so: (null):0 ((null)): QSqlDatabase: QSQLITE driver not loaded
    W libsplinechart.so: (null):0 ((null)): QSqlDatabase: available drivers:
    W libsplinechart.so: (null):0 ((null)): QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
    W libsplinechart.so: (null):0 ((null)): QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
    D libsplinechart.so: ../splinechart/devicedata.cpp:55 (DeviceData::DeviceData(QObject*)): Error: connection with database fail
    W libsplinechart.so: (null):0 ((null)): qt.bluetooth: Connecting to port is not supported
    I libsplinechart.so: ../splinechart/devicedata.cpp:190 (int DeviceData::syncDeviceData(bool)): State 3
    W libsplinechart.so: (null):0 ((null)): QSqlQuery::exec: database not open


  • Moderators

    @Avtansh-Sharma said in Sample Sqlite Database Application:

    W : (null):0 ((null)): WARNING: QApplication was not created in the main() thread.

    What is this? Do you create QApplication instance in another thread?



  • I created QApplication and DeviceData(Sql commands) class in same thread.

    #include <QtWidgets/QApplication>
    #include <QtWidgets/QMainWindow>
    #include <QtCharts/QChartView>
    #include <QtCharts/QSplineSeries>
    #include <devicedata.h>
    #include <QThread>
    #include <devicethread.h>
    #include <themewidget.h>
    #include <QtCore/QtPlugin>
    //DeviceData obj_DeviceData;
    QT_CHARTS_USE_NAMESPACE
    //Q_IMPORT_PLUGIN(qsqlite)

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QMainWindow window;
    ThemeWidget *widget = new ThemeWidget();
    window.setCentralWidget(widget);
    
    window.resize(900, 600);
    window.show();
    DeviceData obj_DeviceData;
    obj_DeviceData.syncDevice(true);
    
    return a.exec();
    

    }

    Constructor of DeviceData

    DeviceData::DeviceData(QObject *parent)
    : QObject(parent), m_bluetoothSocket(0)
    {

    if (QSqlDatabase::drivers().isEmpty())
           qInfo()<<("This demo requires at least one Qt database driver. "
                                       "Please check the documentation how to build the "
                                       "Qt SQL plugins.");
    try
    {
    m_bterminate=false;
    qDebug() << QSqlDatabase::drivers();
    m_db = QSqlDatabase::addDatabase("QSQLITE","SQLITE");
    
    //m_db.setDatabaseName("/home/user/db_Health.db");
    
    QString basePath = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)[1];
    m_db.setDatabaseName(basePath+"/db_Health.db");
    if (!m_db.open())
    {
        qDebug() << "Error: connection with database fail";
        QSqlError error= m_db.lastError() ;
        qInfo()<<error;
    
    }

Log in to reply
 

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