Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    QFileSystemModel problem with rowCount

    General and Desktop
    3
    4
    1759
    Loading More Posts
    • 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.
    • S
      sebvey last edited by

      Dear all,

      I am learning how to use model/view with the Qt documentation
      (http://doc.qt.digia.com/qt/model-view-programming.html)

      But I can't make one example working :

      I create a QFileSystemModel, set the root path and want to know the number of rows of an index, here is the main code :

      @QApplication app(argc, argv) ;

      QFileSystemModel* model = new QFileSystemModel ;
      model->setRootPath(QDir::currentPath()) ;

      QModelIndex parentIndex = model->index(QDir::currentPath()) ;
      int rows = model->rowCount(parentIndex) ;
      qDebug() << rows ;

      return app.exec() ;
      @
      rows is always set to 0, no matter the path. I think I'm using the code of the example without any changes so if someone can help me it would be a pleasure.

      1 Reply Last reply Reply Quote 0
      • L
        leon.anavi last edited by

        Make sure that your current directory is not empty or change the root path.

        http://anavi.org/

        1 Reply Last reply Reply Quote 0
        • S
          sebvey last edited by

          I have found some explanations on the internet...

          the QFileSystemModel::rowCount() function apparently return a valid result only after app.exec() is called.

          Replacing the QFileSystemModel with a QDirModel, (without using setRootPath() work well.

          That's the way to make the example of "Model/View Programming" working. (QDirModel is obsolete for the rest)

          1 Reply Last reply Reply Quote 0
          • musimbate
            musimbate last edited by

            If you are learning from the examples ,a thing I have found helpful is to load the examples from your install directory ,run them and figure out how they have achieved what you have already seen working.
            Just find the examples folder in your install.Help examples also have a link to the location of the files of the examples.

            I love the Qt help system.It is just so logical.

            Why join the navy if you can be a pirate?-Steve Jobs

            1 Reply Last reply Reply Quote 0
            • First post
              Last post