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. [solved] Why rowCount() of QFileSystemModel always return 0
Forum Updated to NodeBB v4.3 + New Features

[solved] Why rowCount() of QFileSystemModel always return 0

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.2k 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.
  • H Offline
    H Offline
    Hareen Laks
    wrote on 17 Dec 2014, 08:04 last edited by
    #1

    Hi,

    While reading "this":http://qt-project.org/doc/qt-4.8/model-view-programming.html#using-model-indexes I tried to code the example.

    @QFileSystemModel *model = new QFileSystemModel;
    QModelIndex parent_index = model->index(QDir::currentPath());
    int num_rows = model->rowCount(parent_index);@

    But num_rows always give me 0.

    Kindly request your guidance.

    Thanks you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Dec 2014, 08:19 last edited by
      #2

      Hi,

      QFileSystemModel's loading is done asynchronously you have to at least wait for the directoryLoaded signal to be emitted before checking that kind for thing

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • H Offline
        H Offline
        Hareen Laks
        wrote on 17 Dec 2014, 10:24 last edited by
        #3

        Thank you SGaist it solved my issue.

        I use.

        @connect(model,SIGNAL(directoryLoaded(QString)),this,SLOT(findItems(QString)));@

        "QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Calls to rowCount() will return 0 until the model populates a directory."

        I should read document first.

        1 Reply Last reply
        1

        1/3

        17 Dec 2014, 08:04

        • Login

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