Results 1 to 7 of 7

Thread: Qdirmodel issue

  1. #1
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Qdirmodel issue

    Hi
    I am facing a strange issue in the QDIRMODEL
    I have written the below code on the SLOT function for the button SIGNAL( clicked), but when I run the code , the tree doesnt show and when I debug the code
    QDirModel model
    goes into qgrayraster

    Qt Code:
    1. QDirModel model;
    2. QTreeView tree;
    3. tree.setModel(model);
    4. tree.setRootIndex(model->index(QDir::homePath()));
    5. tree.setColumnHidden( 1, true );
    6. tree.setColumnHidden( 2, true );
    7. tree.setColumnHidden( 3, true );
    8. tree.setWindowTitle(QObject::tr("Dir View:")+QDir::homePath());
    9. tree.resize(640, 480);
    10. tree.show();
    To copy to clipboard, switch view to plain text mode 

    May I know where am I going wrong

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qdirmodel issue

    Probably basic C++ issue: Have a look at the difference of creating objects on the stack or heap. Also look at the lifetime of these objects!

  3. #3
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Qdirmodel issue

    but even when I do
    QDirModel* model = new QDirModel;

    I still get the same issue

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qdirmodel issue

    Then you must show us the full code of your slot.

  5. #5
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Qdirmodel issue

    Class Declaration
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. MainWindow(QWidget *parent = 0);
    6. ~MainWindow();
    7. public:
    8. void createMenu();
    9.  
    10. public slots:
    11. void FileBrowseWindow();
    12. void ClearButton();
    13.  
    14. private:
    15. QLabel* namelabel;
    16. QTextEdit* nametext;
    17. QLabel* loclabel;
    18. QTextBrowser* locText;
    19. QPushButton* browse_button;
    20. QPushButton* ok_button;
    21. QPushButton* cancel_button;
    22.  
    23. };
    To copy to clipboard, switch view to plain text mode 


    constructor
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent):
    2. QMainWindow(parent)
    3. {
    4. namelabel = new QLabel("Name",this);
    5. nametext = new QTextEdit(this);
    6. loclabel = new QLabel("Location",this);
    7. locText = new QTextBrowser(this);
    8. browse_button = new QPushButton("Browse",this);
    9. ok_button = new QPushButton("Ok",this);
    10. cancel_button = new QPushButton("Cancel",this);
    11. createMenu();
    12. connect(browse_button,SIGNAL(clicked()),SLOT(FileBrowseWindow()),Qt::DirectConnection);
    13. //connect(cancel_button,SIGNAL(clicked()),this,SLOT(ClearButton()),Qt::AutoConnection);
    14. }
    To copy to clipboard, switch view to plain text mode 

    SLOT function
    Qt Code:
    1. void MainWindow::FileBrowseWindow()
    2. {
    3. QDirModel* model = new QDirModel(this);
    4. QTreeView tree;
    5. tree.setModel(model);
    6. tree.setRootIndex(model->index(QDir::homePath()));
    7. tree.setColumnHidden( 1, true );
    8. tree.setColumnHidden( 2, true );
    9. tree.setColumnHidden( 3, true );
    10. tree.setWindowTitle(QObject::tr("Dir View:")+QDir::homePath());
    11. tree.resize(640, 480);
    12. tree.show();
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qdirmodel issue

    Well, it isn't enough to create the model on the heap. You should probably also create the tree on the heap...

  7. #7
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default [SOLVED ] Qdirmodel issue

    thanks
    solved the problem

Similar Threads

  1. QDirModel - add own items
    By heinz32 in forum Newbie
    Replies: 11
    Last Post: 15th May 2008, 11:23
  2. QDirModel and FTP
    By last2kn0 in forum Qt Programming
    Replies: 5
    Last Post: 19th April 2008, 00:02
  3. QDirModel
    By rvb13 in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 16:03
  4. QDirModel
    By L.Marvell in forum Newbie
    Replies: 2
    Last Post: 5th June 2007, 14:47
  5. QDirModel and a QTreeView.
    By jamd in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 09:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.