Results 1 to 4 of 4

Thread: Application with QSqlLite data base

  1. #1
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Application with QSqlLite data base

    I am developing an application with QSqlLite data base. My question is that if i create the executable file of that code so that it can run on other machine, is it possible to run it on other system without any other requirement.
    my other problem is

    When I tried running my code in debug mode it is running fine but when ever i am setting it to be in release mode it is showing me error no data base found. Also i would like to tell is that i configured my qt to generate standalone executables

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Application with QSqlLite data base

    If you deploy a Qt program correctly then all it dependencies are installed with it. The user should have to manually deploy anyhting else.

    Well, the database is not where you told Qt to look... probably because you are using a relative path and assuming the current working directory is where you think it is.

    Also i would like to tell is that i configured my qt to generate standalone executables
    I have no idea what this means. Is it a question or statement?
    Last edited by ChrisW67; 17th January 2014 at 21:00.

  3. #3
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Application with QSqlLite data base

    bool Configure_mainWindow::setupDb(QString dbname)
    {



    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(dbname);

    if(db.open())
    {

    bool found = false;
    foreach (QString table, db.tables())
    {
    if(table == "sonar")
    {
    found = true;
    break;
    }
    }
    if(!found)
    {
    QSqlQuery query(db);
    query.exec("CREATE TABLE sonar (sonar VARCHAR(32), beamAngle VARCHAR(16),beamElevation VARCHAR(32),frequency VARCHAR(32),sourceLevel VARCHAR(32), directivityIndex VARCHAR(32),detThreshold VARCHAR(32))");
    // query.exec("CREATE TABLE environmentData (latMin VARCHAR(32), latMax VARCHAR(16),lngMin VARCHAR(32),lngMax VARCHAR(32),bottomDepth VARCHAR(32), bottomType VARCHAR(32),bottomSlopeDirection VARCHAR(32),bottomSlopeAngle VARCHAR(32),salinity VARCHAR(32),pH VARCHAR(32))");

    }

    model = new QSqlTableModel(this,db);
    model->setTable("sonar");

    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();


    }
    else
    return false;

    return true;
    }
    this is my function for creating database, when i set the project configuration in debug mode it is returning "true" but when ever i set my configuration in release mode it is giving me error.
    also i am calling this function in the constructor like this
    QString filename = QDir::currentPath()+"/Velocity Profiles"+ "sonar.db";;
    if(!setupDb(filename))
    {
    QMessageBox::critical(this,tr("Database not found"),tr("Database not found. The application will be closed."),QMessageBox::Ok);
    qApp->exit();
    }

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Application with QSqlLite data base

    As I said in my first post, QDir::currentPath() is probably not where you think it is. Consequently, trying to create "Velocity Profilessonar.db" is probably failing.

Similar Threads

  1. data base in qt
    By Fafa in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2011, 00:52
  2. Sqlite data base
    By sabbu in forum Newbie
    Replies: 14
    Last Post: 26th May 2011, 01:17
  3. Sqlite data base
    By sabbu in forum Newbie
    Replies: 2
    Last Post: 19th May 2011, 23:43
  4. Sqlite data base
    By sabbu in forum Qt Programming
    Replies: 5
    Last Post: 19th May 2011, 11:57
  5. QTable - Data Base Problem
    By esq in forum Qt Tools
    Replies: 9
    Last Post: 27th May 2007, 23:08

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
  •  
Qt is a trademark of The Qt Company.