Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Strange problem in QML calling C++ function..
Forum Updated to NodeBB v4.3 + New Features

Strange problem in QML calling C++ function..

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 622 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BBFAG3
    wrote on last edited by
    #1

    @
    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 problem

    but 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&#40;&#41;;
    

    }
    @

    this is main.cpp

    [Edited - Please use code tags "@@" - p3c0]

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      What is urlSelectorr ?

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved