Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 744357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:58:08+00:00 2026-05-14T08:58:08+00:00

EDIT2: model.hasChildren(parentIndex) returns True , but model.rowCount(parentIndex) returns 0 . Is QFileSystemModel just fubar

  • 0

EDIT2: model.hasChildren(parentIndex) returns True, but model.rowCount(parentIndex) returns 0. Is QFileSystemModel just fubar in PyQt?

EDIT: With a bit of adaptation this all works exactly as it should if I use QDirModel. This is deprecated, but maybe QFileSystemModel hasn’t been fully implemented in PyQt?


I’m learning the Qt Model/View architecture at the moment, and I’ve found something that doesn’t work as I’d expect it to. I’ve got the following code (adapted from Qt Model Classes):

from PyQt4 import QtCore, QtGui

model = QtGui.QFileSystemModel()

parentIndex = model.index(QtCore.QDir.currentPath())
print model.isDir(parentIndex) #prints True
print model.data(parentIndex).toString() #prints name of current directory

rows = model.rowCount(parentIndex)
print rows #prints 0 (even though the current directory has directory and file children)

The question:

Is this a problem with PyQt, have I just done something wrong, or am I completely misunderstanding QFileSystemModel? According to the documentation, model.rowCount(parentIndex) should return the number of children in the current directory. (I’m running this under Ubuntu with Python 2.6)

The QFileSystemModel docs say that it needs an instance of a Gui application, so I’ve also placed the above code in a QWidget as follows, but with the same result:

import sys
from PyQt4 import QtCore, QtGui

class Widget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        model = QtGui.QFileSystemModel()

        parentIndex = model.index(QtCore.QDir.currentPath())
        print model.isDir(parentIndex)
        print model.data(parentIndex).toString()

        rows = model.rowCount(parentIndex)
        print rows


def main():
    app = QtGui.QApplication(sys.argv)
    widget = Widget()
    widget.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:58:08+00:00Added an answer on May 14, 2026 at 8:58 am

    I’ve solved it.

    The reason to use QFileSystemModel as opposed to QDirModel is because QFileSystemModel loads the data from the filesystem in a separate thread. The problem with that is that if you try to print the number of children just after it’s been constructed is that it won’t have loaded the children yet. The way to fix the above code is to add the following:

    self.timer = QtCore.QTimer(self)
    self.timer.singleShot(1, self.printRowCount)
    

    to the end of the constructor, and add a printRowCount method which will print the correct number of children. Phew.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Html.ActionLink <li> ${Html.ActionLink<HomeController>(c => c.Edit(ViewData.Model.Id, ViewData.Model.Title), Edit)} </li> When created as html shows
I run script/generate model query edit query.rb in models.. class Query < ActiveRecord::Base #I
I am using a nested model form to edit all phone numbers of a
@RequestMapping(value = {/userDetails, /userDetails/edit/{id}}, method = RequestMethod.GET) public String userDetails(Map Model,****) { //what goes
When you enter edit mode for a UITableView (grouped but I believe this applies
EDIT3: To wit, DO NOT put migration code in your model.rb files!!! EDIT2: THE
EDIT1 : I tried doing sqlflush to reset everything, but that didn't help. EDIT2
Is there any ready apps for django admin, that allows to edit model in
In this model class Rep(db.Model): mAUTHOR = db.UserProperty(auto_current_user=True) mUNIQUE = db.StringProperty() mCOUNT = db.IntegerProperty()
I have a template like this: <a class=btn btn-info btn-small edit model-id=<%= model.id %>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.