Solved

SetRootPath with QT, QFileSystemModel  on Mac OS X

Posted on 2012-03-26
3
642 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
If you other experts are anything like me you are always looking into and testing out new features. While I was doing some research one day I ran across an app that I installed on my Mac and used as a security system. Mac OS X: SecureHome uses your …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

730 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