blackberry 10 - BBOS 10 File picker not returning signals properly -
i implemented native file picker on blackberry 10, after bit of messing around recognised class, opens fine , returns file address on console looks 2 signals not working properly, baring in mind pretty straight copy of code blackberry 10 docs.
using namespace bb::cascades::pickers; void utils::getfile() const{ filepicker* filepicker = new filepicker(); filepicker->settype(filetype::music); filepicker->settitle("select sound"); filepicker->setmode(filepickermode::picker); filepicker->open(); // connect fileselected() signal slot. qobject::connect(filepicker, signal(fileselected(const qstringlist&)), this, slot(onfileselected(const qstringlist&))); // connect canceled() signal slot. qobject::connect(filepicker, signal(canceled()), this, slot(oncanceled())); }
i wanted return file url qml (works fine qfiledialog wouldn't recognise on sdk) var test=utils.getfile() if(test=="") console.debug("empty") else console.debug(test)
but i'm getting these messages console: object::connect: no such slot utils::onfileselected(const qstringlist&) in ../src/utils.cpp:27 object::connect: no such slot utils::oncanceled() in ../src/utils.cpp:33
it returning undefined else in qml function when opens, know cocked or how qfiledialog class found sdk?
i wanted give bit of explanation in case you're still having troubles. concept's in qt little foreign me when started in on well.
there couple ways can this. easiest pure qml route:
import bb.cascades 1.2 import bb.cascades.pickers 1.0 page { attachedobjects: [ filepicker { id: filepicker type: filetype.other onfileselected: { console.log("selected files: " + selectedfiles) } } ] container { layout: docklayout { } button { id: launchfilepicker text: qstr("open filepicker") onclicked: { filepicker.open(); } } } }
when click launchfilepicker
button, invoke filepicker. once file selected, fileselected
signal fired. slot
in case onfileselected
function (predefined), logs filepaths of files selected (a parameter signal) console.
the c++ route little more work, still doable.
if class file called util
, you'd have util.h
looks this:
#ifndef util_h_ #define util_h_ #include <qobject> class qstringlist; class util : public qobject { q_object public: util(qobject *parent = 0); q_invokable void getfile() const; private q_slots: void onfileselected(const qstringlist&); void oncanceled(); }; #endif /* util_h_ */
note q_invokable getfile()
method. q_invokable allow call method directly qml.
the corresponding util.cpp
like:
#include "util.h" #include <qdebug> #include <qstringlist> #include <bb/cascades/pickers/filepicker> using namespace bb::cascades; using namespace bb::cascades::pickers; util::util(qobject *parent) : qobject(parent) { } void util::getfile() const { filepicker* filepicker = new filepicker(); filepicker->settype(filetype::other); filepicker->settitle("select file"); filepicker->setmode(filepickermode::picker); filepicker->open(); qobject::connect( filepicker, signal(fileselected(const qstringlist&)), this, slot(onfileselected(const qstringlist&))); qobject::connect( filepicker, signal(canceled()), this, slot(oncanceled())); } void util::onfileselected(const qstringlist &stringlist) { qdebug() << "selected files: " << stringlist; } void util::oncanceled() { qdebug() << "oncanceled"; }
to make q_invokable getfile()
method available qml, you'd need create instance , set contextproperty. in applicationui.cpp
so:
util *util = new util(app); qmldocument *qml = qmldocument::create("asset:///main.qml").parent(this); qml->setcontextproperty("_util", util);
then, can call q_invokable getfile()
method qml:
page { container { layout: docklayout {} button { id: launchfilepicker text: qstr("open filepicker") onclicked: { _util.getfile(); } } } }
like richard says, of documentation covers how create signals/slots, review that, have @ cascades-samples on git.
hope helps!!!
Comments
Post a Comment