Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileSystemModel problem with rowCount

QFileSystemModel problem with rowCount

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k Views
  • 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 Offline
    S Offline
    sebvey
    wrote on last edited by
    #1

    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
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

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

      http://anavi.org/

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sebvey
        wrote on last edited by
        #3

        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
        0
        • musimbateM Offline
          musimbateM Offline
          musimbate
          wrote on last edited by
          #4

          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
          0

          • Login

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