Results 1 to 4 of 4

Thread: SQLITE database problems

  1. #1
    Join Date
    Apr 2007
    Posts
    4
    Qt products
    Qt4

    Default SQLITE database problems

    Hello all,

    I am using QT4 and kdevelop3.4 to connect to a sqlite database. Following is my code, and i get some errors as i listed below.

    Connection.h
    #ifndef CONNECTION_H
    #define CONNECTION_H

    #include <QMessageBox>
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QSqlQuery>
    #include <QSqlRecord>
    #include <QVariant>

    static bool createConnection()
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("/home/LInux-ADVS5/advs -joe/RealBasic/IntialWizard/advsdb_1.rbd");
    if (!db.open()) {
    QMessageBox::critical(0, qApp->tr("Cannot open database"),
    qApp->tr("Unable to establish a database connection.\n"
    "This example needs SQLite support. Please read "
    "the Qt SQL driver documentation for information how "
    "to build it.\n\n"
    "Click Cancel to exit."), QMessageBox::Cancel);
    return false;
    }
    return true;
    }

    main.cpp
    #include <QApplication>
    #include "connection.h"
    #include "main_application.h"

    #include <QSqlQuery>
    #include <QSqlRecord>





    int main(int argc, char *argv[])
    {
    QString str,name,s;
    QApplication app(argc, argv);
    main_application * mw = new main_application();
    if (!createConnection())
    return 1;

    QSqlQuery q("select * from AlarmAction");
    QSqlRecord recordSet = q.record();
    int rec = recordSet.count();

    qDebug("count is = %d", rec);

    int nameCol = recordSet.indexOf("ID"); // index of the field "name"
    while (q.next())
    {
    qDebug("names are:%s", q.value(nameCol).toString());
    }

    mw->show();
    return app.exec();
    }


    The warning msg i get is
    main.cpp:52: warning: cannot pass objects of non-POD type ‘class QString’ through ‘...’; call will abort at runtime


    am i overlooking something?
    I am a newbie in QT4. Thanks in advance for your help..

    --PH

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLITE database problems

    As far I can see, your problem is right about here:
    Qt Code:
    1. qDebug("names are:%s", q.value(nameCol).toString());
    To copy to clipboard, switch view to plain text mode 

    Formatting with %s requires const char*. QString does not have an operator const char*, so you must use:
    Qt Code:
    1. qDebug("names are:%s", q.value(nameCol).toString().toAscii().constData());
    To copy to clipboard, switch view to plain text mode 

    BTW: could you use code tags for source code. It is more readable that way.

    Regards

  3. #3
    Join Date
    Apr 2007
    Posts
    4
    Qt products
    Qt4

    Default Re: SQLITE database problems

    Thanks a lot for your help. It works now..
    I shall use code tags for source code from now on.

    Thanks again..

    --PH

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLITE database problems

    You're welcome.

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. Bulk insert into SQLite
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 19th November 2007, 03:56
  3. Reading umlaut letters from sqlite database
    By Djony in forum Qt Programming
    Replies: 11
    Last Post: 17th November 2006, 10:30
  4. Sqlite & QPixmap Help please
    By munna in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2006, 05:35
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.