Solved

SetRootPath with QT, QFileSystemModel  on Mac OS X

Posted on 2012-03-26
3
646 Views
Last Modified: 2012-03-31
I'm trying to create a file explorer in qt which is working but I cannot set the root path. I am running Mac OS X and no matter what root path I put in, the treeView always begins with

 "/" the top folder.

I've spent 2 hours trying to figure this out.

if(QDir("SavedOutlines").exists()){
        fileModel = new QFileSystemModel;
        QDir dir;
        QString rootpath = dir.absolutePath() + "/SavedOutlines/";
        //QString path = "/Users/";
        fileModel = new QFileSystemModel(this);

        QModelIndex idx = fileModel->setRootPath(rootpath);
        ui->treeView->setCurrentIndex(idx);
        ui->treeView->setModel(fileModel);
        ui->treeView->show();
    }

Open in new window


It seems like it's doing it at first but then resetting back to the top directory.
0
Comment
Question by:falimorad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 37768000
Stupid question - what happens if you try that with a hard-coded path?
0
 

Accepted Solution

by:
falimorad earned 0 total points
ID: 37768010
Doesn't work.

I found that the below code works:

QDir directory;
    directory.setPath(directory.absolutePath() + "/SavedOutlines/");
    ui->listWidget->addItems(directory.entryList());
    //removes the . and .. folders
    delete ui->listWidget->item(0);
    delete ui->listWidget->item(0);

Open in new window

0
 

Author Closing Comment

by:falimorad
ID: 37790397
This works to populate a list of files in a folder.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question