?
Solved

SetRootPath with QT, QFileSystemModel  on Mac OS X

Posted on 2012-03-26
3
Medium Priority
?
657 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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 …

770 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