Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Filebrowser using QML
Forum Updated to NodeBB v4.3 + New Features

Filebrowser using QML

Scheduled Pinned Locked Moved QML and Qt Quick
12 Posts 6 Posters 11.9k 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.
  • A Offline
    A Offline
    Arifa
    wrote on last edited by
    #1

    Could some one please help me out in implementing Filebrowser in QML.
    Currently this is what is being done:

    main.cpp

    @
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QFileSystemModel *model = new QFileSystemModel();
    model->setRootPath("/home/user/");
    QDeclarativeView view;
    QDeclarativeEngine *engine = view.engine();
    QDeclarativeContext *context = view.rootContext();
    context->setContextProperty("qml_model",model);
    view.setSource(QUrl::fromLocalFile("example.qml"));
    QObject rootObject = dynamic_cast<QObject>(view.rootObject());
    view.setGeometry(QRect(0,0,840,480));
    view.showFullScreen();
    return app.exec();
    }
    @

    example.qml:

    @
    Rectangle {

        id:file10
        width: 840
        height: 240
        x: 0
        y: 100
    
    
       ListView {
             id: view
             width: 840
             height: 240
             highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
             focus: true
    
             model: VisualDataModel {
                 model: qml_model
                 delegate: Rectangle {
                     width: 100; height: 100
                       Text  { text: fileName ;  anchors.horizontalCenter: parent.horizontalCenter }
                     MouseArea {
                         anchors.fill: parent
                         onClicked: {
                             if (model.hasModelChildren) {
                                 view.model.rootIndex = view.model.modelIndex(index)
                            }
                             else {
                                 console.log("no folders")
                             }
                         }
                     }
                 }
             }
         }
    }
    

    @

    The problem is i do not get to browse inside /home/user/ even if there are multiple folders.And my starting point is always '/' and not /home/user as I have mentioned in .cpp

    [EDIT: code formatting, please use @-tags, Volker]

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kamalakshantv
      wrote on last edited by
      #2

      Please format your code. Will help others to read and understand it better.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arifa
        wrote on last edited by
        #3

        [Deleted duplicate content, fix the original post - there is an edit link below your username and avatar on every post or comment you write. Volker]

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sanjayrathore36
          wrote on last edited by
          #4

          thanks .I think this post is really help full.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mbrasser
            wrote on last edited by
            #5

            Hi,

            I'd suggest taking a look at the FolderListModel element if you haven't done so already (http://doc.qt.nokia.com/4.7-snapshot/qml-folderlistmodel.html). You can find an example of its use in the qmlviewer application (the QML files are in the source tree under tools/qml/browser).

            In regards to model->setRootPath("/home/user/"), from the documentation it looks like this function only determines what directory is watched by the model for changes, and doesn't impact what is exposed to/shown by the view (rootIndex needs to be set for that).

            Regards,
            Michael

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kyleplattner
              wrote on last edited by
              #6

              I am assuming this is the dialog used on the qmlviewer application when file--> open is selected?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mbrasser
                wrote on last edited by
                #7

                [quote author="kyleplattner" date="1296434643"]I am assuming this is the dialog used on the qmlviewer application when file--> open is selected?[/quote]

                It depends on the platform as to what qmlviewer shows by default. You can explicitly turn on the QML-based file browser by passing -qmlbrowser to qmlviewer.

                Regards,
                Michael

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Arifa
                  wrote on last edited by
                  #8

                  Thanks alot with folder list model as an example my sample is now working

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Arifa
                    wrote on last edited by
                    #9

                    An issue which actually occurred now is when I create a new folder or file it does not refresh at that time but need to reopen my sample again.

                    Is there a way to refresh or we need to implement a separate button for it?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alexander
                      wrote on last edited by
                      #10

                      It's strange because: QFileSystemModel keeps a cache with file information. The cache is automatically kept up to date using the QFileSystemWatcher.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Arifa
                        wrote on last edited by
                        #11

                        Yes using QFileSysytemModel it works but currently I am using QML (folderlist model)
                        where I am actually setting the folder path as we go into the folders but still it does not work

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Arifa
                          wrote on last edited by
                          #12

                          I have actually raised a bug for the issue http://bugreports.qt.nokia.com/browse/QTBUG-17141

                          1 Reply Last reply
                          0

                          • Login

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