2 Attachment(s)
[solved]Get filepath and filename from qtreewidget
Hi
I have a strange issue where I need to get filepath and filename on a single click of the item in the qtreewidget
Code:
{
Q_OBJECT
public:
browserwindow
(QWidget* parent
= 0);
~browserwindow();
//functions
void populate();
public slots:
public:
};
Code:
#include "browsemodel.h"
browserwindow
::browserwindow(QWidget* parent
){
populate();
}
browserwindow::~browserwindow()
{
delete tree;
delete model;
}
void browserwindow::populate()
{
tree->setModel(model);
tree
->setRootIndex
(model
->index
(QDir::homePath()));
tree->setWindowTitle("Browse for folder");
tree->resize(820, 7200);
}
QModelIndex browserwindow
::getDetails(const QModelIndex &index
) // to get details on the index on single click {
QString filename
= model
->fileName
(index
);
return model->index(0);
}
Issue is that I get a SIGSERV segmentation fault when I run the above code
my main objective is that , when a user clicks on the "browse" button(add_link_folder.png), the browser should open(browser.png)
when the user single clicks on any file in the browser, it should go back to the (add_link_folder.png) and the location and name shud display the filepath and filename respectivly
Re: Get filepath and filename from qtreewidget
You don't need to delete tree and model. They get deleted by Qt. Further what is the purpose of subclassing QTreeWidget and create a QTreeView inside? Also do you have seen QFileDialog?
And where exactly crashes the program?
Re: Get filepath and filename from qtreewidget
1) I needed to display the filesystem , and therefore I used a QDirModel and QTreeView to display the filesystem
The filesystem gets displayed in a new window(browser.png)
2) QFileDialog would provide me a dialog box where I can select specific files and directories , but my objective is to display the filesystem in a tree view , select a specific file from the treeview , the selected file name and path would be displayed in a text browser
The crash happens at
connect(this,SIGNAL(clicked(QModelIndex)),SLOT(get Details(QModelIndex)),Qt::DirectConnection);
Re: Get filepath and filename from qtreewidget
well within the posted code I don't see an error. Can you post the backtrace since it isn't (most likely) the connection statement.