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 6010123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:04:17+00:00 2026-05-23T02:04:17+00:00

I’m using Qt 4.6 within Ruby (via QtRuby) and am trying to make a

  • 0

I’m using Qt 4.6 within Ruby (via QtRuby) and am trying to make a generic Directory Selection Dialog which displays a small “loading” glyph whilst the file system is being queried and the Directory Tree (QTreeView) is being updated.

UPDATE: I must say that the animation doesn’t work as expected, is there another way of detecting these events (loading, loaded) ? See “On another note” below.

I have managed to connect the “new directories loaded” event via the rowsInserted Signal of the used QFileSystemModel, works quite fine. I’m also able to catch the “loading new directories” event via the rowsAboutToBeInserted signal. Yet the animation I’m trying to play (a simple animated GIF to indicate progress, loaded within a QMovie) is getting played even if the directory which has been ‘expanded’ is empty. Here is the code I am using :

# FileSystemModel extension which shows a 'busy' animation
# in a given Qt::Label
class FileSystemModelEx < Qt::FileSystemModel

  # Slot declarations
  slots "handle_ready(QModelIndex, int, int)"
      slots "handle_busy(QModelIndex, int, int)"

  # Parametrised constructor, initializes fields
  def initialize(p_parent, p_label, p_busy_icon, p_ready_icon)

      # Call superclass constructor
      super(p_parent)

      # Set instance vars
      @label = p_label
      @busy_icon = p_busy_icon
      @ready_icon = p_ready_icon

      # Connect 'finished loaded' event
      Qt::Object.connect(self,
                        SIGNAL('rowsAboutToBeInserted(QModelIndex, int, int)'),
                        self,
                        SLOT('handle_busy(QModelIndex, int, int)'))

      # Connect 'loading' event
      Qt::Object.connect(self, 
                        SIGNAL('rowsInserted(QModelIndex, int, int)'),
                        self,
                        SLOT('handle_ready(QModelIndex, int, int)'))
  end

  # Loading finished event, changes icon state to ready
  def handle_ready(p_index, p_start, p_end)
      set_icon(false)   

      puts "    done - loaded #{rowCount(p_index)} folders"
  end

  # Loading started event, changes icon state to busy
  def handle_busy(p_index, p_start, p_end)
      set_icon(true)

      path = fileInfo(p_index).canonicalFilePath
    puts "Loading . . . path = '#{path}'"
  end

  # Overriden start loading event
  def fetchMore(p_index)
      handle_busy(p_index, nil, nil)
      super(p_index)
  end

  # Utility method, switches icons, depending on a given state
  def set_icon(p_busy) 
      movie = (p_busy ? @busy_icon : @ready_icon)
      @label.setMovie(movie)
      movie.start
  end   

end # class FileSystemModelEx

My question would be: How can I keep the animation from playing, if the loaded folder is empty? One cannot filter the empty directories beforehand, isn’t that so?

On another note, is there another way of implementing such ‘loading’ / ‘loaded’ event handlers, other than that described above? I’ve looked around the signals, virtuals (fetchMore and canFetchMore, to no avail), scanned the source yet I cannot reach the call which sends the thread on its quest of retrieving more files. Overriding event or timerEvent doesn’t help.

For completion’s sake, here is the QFileSystemModel I’m using as well:

# Creates a FileSystemModel which display folders only
def create_model
    @model = FileSystemModelEx.new(self, 
                @form.iconPlaceholderDir, 
                @loading_icon, @folder_icon)

    @model.setReadOnly(true)
    @model.setFilter(Qt::Dir::NoDotAndDotDot | Qt::Dir::AllDirs)
    @model.setRootPath(Qt::Dir.rootPath)


    @form.shellTreeView.setModel(@model)
end

Any help would be appreciated, thanks in advance!
I can provide further details if the need arises, no problem.

  • 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-23T02:04:18+00:00Added an answer on May 23, 2026 at 2:04 am

    You should try hooking up the model’s directoryLoaded(const QString&) slot. It signals when the directory has been fully processed.

    Sample app with qt4-ruby (2.1.0) build againts Ruby 1.8.7 and Qt 4.7.3

    #!/usr/bin/ruby -w
    require 'Qt4'
    
    class MyObject < Qt::Object
        slots "mySlot(QString)"
        def mySlot(path)
            print "Done loading ", path, "\n"
        end
    end
    
    a = Qt::Application.new(ARGV)
    m = Qt::FileSystemModel.new
    v = Qt::TreeView.new
    m.setRootPath("/")
    v.setModel(m)
    o = MyObject::new
    Qt::Object.connect(m, SIGNAL('directoryLoaded(QString)'), o, SLOT('mySlot(QString)'))
    v.show
    a.exec
    

    (Be kind, this is my very first ruby “program”…)

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

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.