PDA

View Full Version : Application with QSqlLite data base



shivendra46d
17th January 2014, 17:58
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

ChrisW67
17th January 2014, 20:55
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?

shivendra46d
21st January 2014, 06:16
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();
}

ChrisW67
21st January 2014, 08:27
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.