I am using tree view and list view to display the contents of QFilesystem model...
When i used Dialog to display the Tree View and List view , it works properly....
But when i used QMainWindow instead of QDialog, i'm getting run time error saying
"The program has unexpectedly finished."

my code as below...
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QtGui>
  6. #include <QtCore>
  7.  
  8.  
  9. namespace Ui {
  10. class MainWindow;
  11. }
  12.  
  13. class MainWindow : public QMainWindow
  14. {
  15. Q_OBJECT
  16.  
  17. public:
  18.  
  19. explicit MainWindow(QWidget *parent = 0);
  20. ~MainWindow();
  21.  
  22. private slots:
  23.  
  24. void on_treeView_clicked(const QModelIndex &index);
  25.  
  26. private:
  27.  
  28. Ui::MainWindow *ui;
  29. QFileSystemModel *dirmodel;
  30. QFileSystemModel *filemodel;
  31.  
  32. };
  33.  
  34. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 


mainwindow.ui
Qt Code:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>MainWindow</class>
  4. <widget class="QMainWindow" name="MainWindow">
  5. <property name="geometry">
  6. <rect>
  7. <x>0</x>
  8. <y>0</y>
  9. <width>621</width>
  10. <height>591</height>
  11. </rect>
  12. </property>
  13. <property name="windowTitle">
  14. <string>MainWindow</string>
  15. </property>
  16. <widget class="QWidget" name="centralWidget">
  17. <widget class="QTreeView" name="treeView">
  18. <property name="geometry">
  19. <rect>
  20. <x>30</x>
  21. <y>150</y>
  22. <width>311</width>
  23. <height>331</height>
  24. </rect>
  25. </property>
  26. </widget>
  27. <widget class="QListView" name="listView">
  28. <property name="geometry">
  29. <rect>
  30. <x>365</x>
  31. <y>160</y>
  32. <width>231</width>
  33. <height>361</height>
  34. </rect>
  35. </property>
  36. </widget>
  37. </widget>
  38. <widget class="QMenuBar" name="menuBar">
  39. <property name="geometry">
  40. <rect>
  41. <x>0</x>
  42. <y>0</y>
  43. <width>621</width>
  44. <height>21</height>
  45. </rect>
  46. </property>
  47. </widget>
  48. <widget class="QToolBar" name="mainToolBar">
  49. <attribute name="toolBarArea">
  50. <enum>TopToolBarArea</enum>
  51. </attribute>
  52. <attribute name="toolBarBreak">
  53. <bool>false</bool>
  54. </attribute>
  55. </widget>
  56. <widget class="QStatusBar" name="statusBar"/>
  57. </widget>
  58. <layoutdefault spacing="6" margin="11"/>
  59. <resources/>
  60. <connections/>
  61. </ui>
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QtGui>
  4. #include <QtCore>
  5.  
  6.  
  7. MainWindow::MainWindow(QWidget *parent) :
  8. QMainWindow(parent),
  9. ui(new Ui::MainWindow)
  10. {
  11. ui->setupUi(this);
  12.  
  13. QString sPath ="C:/";
  14.  
  15. dirmodel =new QFileSystemModel(this);
  16. dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
  17. dirmodel->setRootPath(sPath);
  18. ui->treeView->setModel(dirmodel);
  19.  
  20.  
  21. filemodel =new QFileSystemModel(this);
  22. filemodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
  23. filemodel->setRootPath(sPath);
  24. ui->listView->setModel(filemodel);
  25.  
  26. }
  27.  
  28. MainWindow::~MainWindow()
  29. {
  30. delete ui;
  31. }
  32.  
  33. void MainWindow::on_treeView_clicked(const QModelIndex &index)
  34. {
  35. QString sPath=dirmodel->fileInfo(index).absoluteFilePath();
  36. ui->listView->setRootIndex(filemodel->setRootPath(sPath));
  37. }
To copy to clipboard, switch view to plain text mode 


Please tell me whats the wrong here..?