Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 13
Registered: ‎02-25-2012
My Device: Blackberry Playbook
My Carrier: ...

QML database problem

Hi,

I have a problem with my QML application on Playbook. I can't create table in my DB. This is my qml code:

//......
function findGreetings() 
{
    var db = openDatabaseSync("DB", "1.0", "Example", 1000000);
    db.transaction (
	function(tx) 
	{
	    tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)', []);     //crashes here
	    tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
	}
    )
}
//..........

 

 

 

 My .pro code:

TARGET = DB
# Add more folders to ship with the application, here
folder_01.source = qml/DB
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01


# The .cpp file which was generated for your project. Feel free to hack it.

QMAKE_LFLAGS += '-Wl,-rpath,\'./app/native/lib\' '

package.target = $${TARGET}.bar
package.depends = $$TARGET
package.commands = blackberry-nativepackager \
   -package $${TARGET}.bar -arg -platform -arg blackberry \
   -devMode -debugToken ./debugToken.bar \
   -arg -platformpluginpath -arg ./app/native/lib/platforms \
   blackberry-tablet.xml $$TARGET \
-e qml qml \
-e icon.png res/icon.png \
   -e /home/dwart/Desktop/QtPlay/lib/libQtCore.so.4 lib/libQtCore.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtGui.so.4 lib/libQtGui.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtOpenGL.so.4 lib/libQtOpenGL.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtNetwork.so.4 lib/libQtNetwork.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtDeclarative.so.4 lib/libQtDeclarative.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtSql.so.4 lib/libQtSql.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtSvg.so.4 lib/libQtSvg.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtScript.so.4 lib/libQtScript.so.4 \
   -e /home/dwart/Desktop/QtPlay/lib/libQtXmlPatterns.so.4 lib/libQtXmlPatterns.so.4 \
   -e /home/dwart/Desktop/QtPlay/plugins/sqldrivers/libqsqlite.so lib/sqldrivers/libqsqlite.so \
   -e /home/dwart/Desktop/QtPlay/plugins/platforms/libblackberry.so lib/platforms/libblackberry.so
QMAKE_EXTRA_TARGETS += package

SOURCES += main.cpp
QT += declarative
QT       += sql
CONFIG += qdeclarative-boostable

# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()

OTHER_FILES += blackberry-tablet.xml

 On desktop my app works great, so why it's doesn't work in playbook? 

 

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QML database problem

It could be a path issue. What's the value of offlineStoragePath there? See http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeengine.html#offlineStoragePath-prop

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 13
Registered: ‎02-25-2012
My Device: Blackberry Playbook
My Carrier: ...

Re: QML database problem

In main.cpp I have code something like QDeclarativeView viewer ->engine()->setOfflineStoragePath("../data"); Instead of "./data" I've tried many different combinations. when I come back home I will write the whole main.cpp

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QML database problem

It's unlikely to be ../data, but just ./data or data should have worked, I think.

 

The paths are, I assume, relative to the current directory.  See http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/BlackBerry-PlayBook-File-System-L... for some background.

 

Can you display the absolute path returned by offlineStoragePath? Maybe it's rooted somewhere other than the app's current directory.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 13
Registered: ‎02-25-2012
My Device: Blackberry Playbook
My Carrier: ...

Re: QML database problem

It's my main.cpp: 

 

#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"

#include <QtSql>
#include <QSqlDatabase>
#include <QSqlQuery>

#include <QDir>
#include <QDeclarativeEngine>


Q_DECL_EXPORT int main(int argc, char *argv[])
{
    qputenv("QT_QPA_FONTDIR", "/usr/fonts/font_repository/liberation");
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
    viewer->setMainQmlFile(QLatin1String("app/native/qml/Fiszki/main.qml"));
    viewer->showFullScreen();
	
	// TESTED PATHS: 
    //viewer->engine()->setOfflineStoragePath("./data");
	//viewer->engine()->setOfflineStoragePath("app/data");
	//viewer->engine()->setOfflineStoragePath("data");
	//viewer->engine()->setOfflineStoragePath("../data");
	//viewer->engine()->setOfflineStoragePath("./../data");
	//viewer->engine()->setOfflineStoragePath("./../../data");
	//viewer->engine()->setOfflineStoragePath("./../../../data");
	//viewer->engine()->setOfflineStoragePath("./../../../../data");
	//viewer->engine()->setOfflineStoragePath("./app/data");
	//viewer->engine()->setOfflineStoragePath("app/data/");
	//viewer->engine()->setOfflineStoragePath("$HOME/data/");
	//viewer->engine()->setOfflineStoragePath("$HOME/Fiszki/data/");
	viewer->engine()->setOfflineStoragePath("Fiszki/data/");
		
    return app->exec();
}

 Now, i'm trying to display offlineStoragePath.

 

Developer
Posts: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Re: QML database problem

[ Edited ]

Perhaps you need to add an env variable to your blackberry-tablet.xml:

<env var="QT_PLUGIN_PATH" value="app/native/lib/plugins"/>

And insert the sql plugin into the libs/plugins folder:

-e /home/dwart/Desktop/QtPlay/plugins/sqldrivers/libqsqlite.so lib/plugins/sqldrivers/libqsqlite.so \

 

And the path in main.cpp I believe should be:

viewer->engine()->setOfflineStoragePath("app/native/data");

 Cheers,

Jon

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QML database problem

jheron, if he's actually trying to create the database, it needs to be in a writable area. Nothing under app/ is writable. See the link I included above.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 40
Registered: ‎01-15-2012
My Device: Playbook Tablet
My Carrier: MTS

Re: QML database problem

[ Edited ]

>>it needs to be in a writable area. Nothing under app/ is writable.

"./data" is writable area. Qt itself and QSettings use it by default to store configuration files.

/rgds
Andrey Yaromenok aka azazello
Contributor
Posts: 13
Registered: ‎02-25-2012
My Device: Blackberry Playbook
My Carrier: ...

Re: QML database problem

Ok, I changed

"<env var="QT_PLUGIN_PATH" value="app/native/lib/"/>"

to "<env var="QT_PLUGIN_PATH" value="app/native/lib/plugins"/>"

and

-e /home/dwart/Desktop/QtPlay/plugins/sqldrivers/libqsqlite.so lib/sqldrivers/libqsqlite.so \

to -e /home/dwart/Desktop/QtPlay/plugins/sqldrivers/libqsqlite.so lib/plugins/sqldrivers/libqsqlite.so \ .

 

In main.cpp I added this:

QDir d;
d.setPath(app->applicationDirPath());
QLabel *label;
label = new QLabel;
		
QString path = d.absolutePath() + "/data";
viewer->engine()->setOfflineStoragePath(path);

label->setText(d.absolutePath() + "\n" + app->applicationDirPath() + "\n" + viewer->engine()->offlineStoragePath());
l->show();

 

 Label showed:

" /accounts/1000/appdata/com.tester.Fiszki.testDev_ster_Fiszki48c4afc   // dir absolute path

 .                                                                                                                                  // applicationDirPath

 /accounts/1000/appdata/com.tester.Fiszki.testDev_ster_Fiszki48c4afc "  // offlineStoragePath

 

Why is offlineSotragePath  "/accounts/....." but not "/accounts/..../data"? I think that's the problem. 

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QML database problem


azazello wrote:

>>it needs to be in a writable area. Nothing under app/ is writable.

"./data" is writable area. Qt itself and QSettings use it by default to store configuration files.


As I said, using. /data should be fine. Nothing under. /app is writable because that's a symlink up to /app/your-app-id and the app has only read/execute permissions there.

 

The app has write access to ./data and. /tmp and nothing else unless the manifest requests access_shared in which case it can also write to. /shared which is itself a symlink to the shared folders (and only the pre-existing subfolders there grant write permissions so you can't create new subfolders directly under. /shared).

 

Hope that helps...


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!