Solved

SetRootPath with QT, QFileSystemModel  on Mac OS X

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mac Online Backups 7 59
Lock session with OS X Sierra 1 51
Content Filtering by Search Term with a Smoothwall Firewall 1 92
designing in object programming 12 42
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 …
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.
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

867 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