[Qt-interest] Sqlite query on Win CE returns no results

Constantin Makshin dinosaur-rus at users.sourceforge.net
Sun Sep 27 22:33:44 CEST 2009


Windows CE doesn't have the "current directory" feature, so there you  
should use absolute paths. IIRC, Qt/WinCE emulates this concept so  
relative paths work when you use Qt's file I/O functions. But SQLite  
driver simply passes the database file path directly to SQLite, which  
obviously doesn't use Qt's workarounds and so searches for files in wrong  
places.

On Sun, 27 Sep 2009 23:56:41 +0400, Andreas Unger <andi.unger05 at gmail.com>  
wrote:
> Apologies, the application works on Win CE as well, albeit with one small
> issue. It looks for the db at the root directory
> instead of the current directory. However, it looks for all the other  
> files
> used in my application in the current directory, which
> is a little weird...
>
> Cheers,
> Andreas
>
> On Sun, Sep 27, 2009 at 3:40 PM, Andreas Unger  
> <andi.unger05 at gmail.com>wrote:
>
>> Hi all,
>>
>> I wrote an app that uses an sqlite database. The dynamically built  
>> applications works well on Linux.
>> The same code doesn't work on Windows CE. Just like on the Linux OS,   
>> SQLITE is listed as one of the
>>
>> supported database drivers in QSqlDatabase::drivers()
>>
>> The only difference here is that the Win CE app is a static build. I'm  
>> able to run the db.open() command,
>> but after that the sql query returns 0 results, even though it runs  
>> multiple results on *nix.
>>
>> I've also tried listing the current folder's content, to make sure that  
>> it does find the sqlite database file,
>> and the file is there alright.
>>
>> I tried the qt demo app, (/demos/sqlbrowser) and it too, doesn't work  
>> on Win CE (loads up but list no query
>>
>> results) yet it works on Linux.
>>
>> Cheers,
>> Andreas
>>
>> ps: Here is the test app:
>>
>> #include <QtGui>
>> #include <QSqlDatabase>
>>
>> #include <QSqlQuery>
>>
>> //"SQLITE" shows up here
>> QString _results = "Supported SQL drivers: ";
>>
>> for (int i = 0; i < QSqlDatabase::drivers().size(); i++){
>>
>>     _results.append(QSqlDatabase::drivers().at(i));
>>
>>
>>     _results.append(" ");
>>
>> }
>>
>> QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
>>
>> db.setDatabaseName("test.db");
>>
>>
>> if (!db.open()) {
>>
>>     QMessageBox::critical(0, qApp->tr("Cannot open database"),
>>
>>             qApp->tr("Unable to establish a database connection.\n\n"
>>
>>                      "Click Cancel to exit."), QMessageBox::Cancel);
>>
>>     return false;
>>
>> }
>>
>>
>>
>> QSqlQuery query;
>>
>> QLabel *_label = new QLabel;
>>
>> _results.append("\n\nSQL Query Results:\n\n");
>>
>> query.exec("SELECT * FROM Test_Items;");
>>
>>
>> while (query.next()) {
>>
>>     _results += query.value(0).toString();
>>
>>     _results.append("\n");
>>
>> }
>>
>>
>>  _label->setText(_results);
>>
>>  _label->show();
>>
>>  return app.exec();
>>
>> }

-- 
Constantin Makshin



More information about the Qt-interest-old mailing list