Solved

SetRootPath with QT, QFileSystemModel  on Mac OS X

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Deploystudio is a system which can be used to deploy OSX clients and servers within the small/medium or large business environments. The system is built ontop of the OSX Server NetBoot system and uses images & workflows as its core assets. Although …
Deploystudio is a system which can be used to deploy OSX clients and servers within the small/medium or large business environments. The system is built onto of the OSX Server NetBoot system and uses images & workflows as its core assets. While work…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now