Important: Please read the Qt Code of Conduct -

Question: write a simple browser of data.

  • Hi,

    I'm developing notifyfs, a fs event monitor and entry cache. The entries do have an index: ordered on name.

    What I want to create is a simple filebrowser with above line to enter the directory, and below that the entries it finds in this directory in the cache. Functions to get the entries are known.

    So after entering the directory in the line above it loads the entries in the "list" under it.
    Howto do this?

    And is it able to export the view parameters back to notifyfs?? I mean the first and the last entry visible in the view?

    Thanks in advance,

    Stef Bon

  • To add info:

    in my console testapplication it's possible to list entries which are stored in a cache, which is accessible via shared memory. After the user enters a path, a starting name, it's a directory or not, and the maximum number to show, the function list_entries is called:

    @void list_entries(char *path, char *name, unsigned char isdir, int maxentries)
    struct notifyfs_entry_struct *parent_entry;

    if (parent_entry) {
        struct notifyfs_entry_struct *entry, *firstentry;
        struct notifyfs_inode_struct *inode;
        struct notifyfs_attr_struct *attr;
        int count=0;
        char *data;
        /* find the best entry based upon name */
        entry=find_entry_raw(parent_entry, inode, name, 0);
        while(entry) {
            if (!attr) {
                fprintf(stdout, "- %-8i %-8i %-8i %s\n", -1, -1, -1, data);
                goto next;
            if (isdir==1) {
                if (! S_ISDIR(attr->cached_st.st_mode)) {
                    entry=get_next_entry(parent_entry, entry);
                    if ( ! entry ) {
                        /* no directory anymore: after directories the other entries */
            } else {
                if ( S_ISDIR(attr->cached_st.st_mode)) {
                    entry=get_next_entry(parent_entry, entry);
            /* print first char */
            if ( isdir==1) {
                fprintf(stdout, "d");
            } else {
                fprintf(stdout, "-");
            /* attributes */
            fprintf(stdout, "%-8i %-8i %-8i", attr->cached_st.st_uid, attr->cached_st.st_gid, attr->cached_st.st_size);
            /* file name */
            fprintf(stdout, "%s",data);
            /* goto next line */
            fprintf(stdout, "\n");
            if (count>maxentries) break;
            entry=get_next_entry(parent_entry, entry);
        if (count==0) {
            fprintf(stdout, "No entries found.\n");
        } else if (count==1) {
            fprintf(stdout, "One entry found.\n");
        } else {
            fprintf(stdout, "%i entries found.\n", count);
    } else {
        fprintf(stdout, "Path %s not found.\n", path);


    Note the entries point to a attr struct via an array index. This is required since shared memory is used. The pointers used by the server (notifyfs) are not valid for the clients, and then some conversion has to be used. This gives too much problems in my case.

    Now howto write a qt app which does the same?

    Note that the data is ordered to name, so it would be good to use that property.
    I know I have to use a model and a view.

    Thanks in advance.

    Stef Bon

  • Do you mean something like "QFileSystemModel": ? Have a look at "this article": about Model/View. Especially the chapter "Using views with an existing model" in the section "Convenience Classes".

  • No, I don't want to use the built in QFileSystemModel. This uses the local filesystem directly, and I want it to use the cache povided by notifyfs, shared via shared memory.

    And I know there are different models and views, but can someone give me a clue howto begin. I'm new to qt. 15 years ago I programmed "gui's" in Clipper, using a browse type and codeblocks to get the entries.

    I have to use something like a QlistBox widget, and assign a QListView to it.

    And then?


  • Ah ok. Then you need to implement your own Model for the ListView. Derive it from a suitable abstract model (see list of classes that inherit "QAbstractItemModel": For more informations just read the "article on Model/View programming in Qt":, it pretty much contains all you need.

  • Thanks for the hint.

    I've found the page about model/view, it contains a lot of information. Isn't there a simple example to show a list (ui design, connect widget with model, assign right data connections/functions with the underlying data)?


  • Sure there are official examples. They are listed at the bottom of "QAbstractItemModels sublassing section":

    Try these:

  • Hi,

    I've also found:

    This is really close to what I'm trying to create. It's using QAbstractListModel


  • Hi,

    I'm looking howto implement it, the function

    QVariant FileListModel::data(const QModelIndex &index, int role) const

    should return the data for a certain indexvalue.

    (this is by the way very confusing, where in the documentation is written index, the indexvalue is meant; the index is the --whole-- list of references of entries, not just an individual value/entry)

    Now, the entries in my datamodel are like a linked list:
    the first entry is:
    entry=get_next_entry(parent_entry, NULL);

    and every next :
    entry=get_next_entry(parent_entry, entry);

    Is it possible to use the previous value (row) of the index (which points to the previous entry)?

    And futher the implementation of shared memory in qt is using the "old" interface: using keys. In my app the newer calls shm_open and shm_unlink are used, which use a filename in stead of a key. Is the new interface also available in qt?


Log in to reply