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;

    parent_entry=check_notifyfs_path(path);
    
    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 */
    
        inode=get_inode(parent_entry->inode);
        entry=find_entry_raw(parent_entry, inode, name, 0);
        firstentry=entry;
    
        while(entry) {
    
            inode=get_inode(entry->inode);
            attr=get_attr(inode->attr);
            data=get_data(entry->name);
    
            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 */
    
                        isdir=0;
                        entry=firstentry;
    
                    }
    
                    continue;
    
                }
    
            } else {
    
                if ( S_ISDIR(attr->cached_st.st_mode)) {
    
                    entry=get_next_entry(parent_entry, entry);
                    continue;
    
                }
    
            }
    
            /* 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");
    
            next:
    
            count++;
    
            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":http://qt-project.org/doc/qt-4.8/qfilesystemmodel.html ? Have a look at "this article":http://doc.qt.digia.com/4.7-snapshot/model-view-programming.html#convenience-classes 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?

    Stef



  • 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":http://doc.qt.digia.com/4.7-snapshot/qabstractitemmodel.html). For more informations just read the "article on Model/View programming in Qt":http://doc.qt.digia.com/4.7-snapshot/model-view-programming.html#model-classes, 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)?

    Stef



  • Sure there are official examples. They are listed at the bottom of "QAbstractItemModels sublassing section":http://doc.qt.digia.com/4.7-snapshot/qabstractitemmodel.html#subclassing.

    Try these:



  • Hi,

    I've also found:

    http://doc.qt.digia.com/4.7-snapshot/itemviews-fetchmore.html

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

    Stef



  • 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?

    Stef


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.