Strange problem in QML calling C++ function..
-
@
onClicked: {
urlSelectorr.appendDir(modelData)
t=urlSelectorr.getNowDir()
console.log(t)
}
@this is my QML code, and the problem is that:
urlSelectorr.appendDir(modelData)
and
urlSelectorr.getNowDir()
can work alone,but if I call appendDir first, getNowDir won't work....
error output is: ReferenceError: urlSelectorr is not defined
it's really confuse me
@
void SPurlSelector::getIntoDir(QString dir)
{
dirList.clear();
QDir seeker(dir);
dirList=seeker.entryList(QDir::Dirs|QDir::NoDotAndDotDot);
ct->setContextProperty("dirList",dirList);
}
void SPurlSelector::appendDir(QString ad)
{
nowDir=nowDir+"/"+ad;getIntoDir(nowDir);
}
QVariant SPurlSelector::getNowDir()
{
return QVariant(nowDir);
}
@this is my C++ code. nowDir is a public QString
And if I change the order of calling,which means I call getNowDir() first, following calling "appendDir" is work too.
I found that is
ct->setContextProperty("dirList",dirList);
cause this problembut I still want to know why...
Sorry for my poor English....
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);QQuickView *view=new QQuickView(); QQmlContext *importer=view->rootContext(); SPplayer player; SPurlSelector urlSelector; importer->setContextProperty("urlSelectorr",&urlSelector); importer->setContextProperty("dirList",urlSelector.dirList); importer->setContextProperty("player",&player); importer->setContextProperty("playList",&player.playList); view->setSource(QUrl("qrc:/qml/SPmain.qml")); QObject *obj=view->rootObject(); QObject *bar = obj->findChild<QObject*>("progressBar"); player.setBar(bar); urlSelector.setIpt(importer); view->setResizeMode(QQuickView::SizeRootObjectToView); view->showFullScreen(); return a.exec();
}
@this is main.cpp
[Edited - Please use code tags "@@" - p3c0]
-
Hi,
What is urlSelectorr ?