PDA

View Full Version : Problem using QSqlDatabase in Symbian



dmendizabal
17th July 2011, 04:26
I’m trying to use the same code that works in my desktop and maemo platform into the symbian OS, but it is not working.
I’m showing below the snipped of the code:


QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("E:/database/01");
qDebug()<<"DB open: "<<db.open();

Result: “DB open: false”

Is there anything to take in consideration in Symbian to create a database file?

DanH
17th July 2011, 14:53
Well, you might need to set the database name correctly. On Symbian database names must be coded Windows style, with the backslash. (Don't forget to double up, since backslash is the "escape" character.)

And where is your database supposed to be? If you want it in the application-private directory you shouldn't code the drive designator or leading slash.

dmendizabal
18th July 2011, 05:16
The Qt specification for paths uses "/" always regardless the targeted OS. In any case I have tried using backslash "\\" but it doesn't work either.

I tested creating a file in this location "E:/database/01.txt" and it worked without a problem. So it shouldn't be a problem of the file system, but something related to the database back-end.

DanH
18th July 2011, 12:59
Symbian is not your desktop. SQLite is not Qt. You should locate the file location with QFileInfo, then use absoluteFilePath to get the path, test that the directory exists with QDir::exists, check that the file exists (if it should) with QFile::exists, then convert slashes with QDir::toNativeSeparators.

You can of course ignore this advice if you wish. I'm not your mother.