Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QTreeview Double Clicked "The program unexpectedly finished"

[SOLVED] QTreeview Double Clicked "The program unexpectedly finished"

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeviewqfilesystemmodedoubleclick
23 Posts 3 Posters 13.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T takoo
    1 Feb 2016, 18:21

    my model a QFileSystemModel.

    This problem not relevant your example :(

    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 1 Feb 2016, 18:26 last edited by
    #4

    @takoo said:
    Ok. you didnt tell.
    are you using any filters ?
    QDir::Filters QFileSystemModel::filter() const

    1 Reply Last reply
    1
    • T Offline
      T Offline
      takoo
      wrote on 1 Feb 2016, 18:32 last edited by
      #5

      I am using QSortFilterProxyModel for filtering

      I just write code ------- (-_-) ----------

      M 1 Reply Last reply 1 Feb 2016, 18:42
      0
      • T takoo
        1 Feb 2016, 18:32

        I am using QSortFilterProxyModel for filtering

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 1 Feb 2016, 18:42 last edited by mrjj 2 Jan 2016, 18:43
        #6

        @takoo
        Hi. well since u can see it, then the filter should be ok.
        Model lives in mainwindow.h? as member?

        I cannot reproduce it.'

          model = new QFileSystemModel();
          model->setRootPath("e:/");
          QListView* view = new QListView();
          view->setModel(model);
          view->setRootIndex(model->index("e:/"));
          view->show();
        
          connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_treeView_doubleClicked(QModelIndex)));
        
        }
        
        void window::on_treeView_doubleClicked(const QModelIndex& index) {
          qDebug() << model->filePath(index);
        }
        
        

        dont crash so you have something in your code.

        1 Reply Last reply
        1
        • T Offline
          T Offline
          takoo
          wrote on 1 Feb 2016, 18:59 last edited by
          #7

          i tryed but was not . I get same error .

          I just write code ------- (-_-) ----------

          M 1 Reply Last reply 1 Feb 2016, 19:03
          0
          • T takoo
            1 Feb 2016, 18:59

            i tryed but was not . I get same error .

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 1 Feb 2016, 19:03 last edited by
            #8

            @takoo
            Hi
            Im not sure what you mean.
            You tried this sample and it still crashes?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              takoo
              wrote on 1 Feb 2016, 19:19 last edited by
              #9

              yes unfourtunely

              I just write code ------- (-_-) ----------

              M 1 Reply Last reply 1 Feb 2016, 19:35
              0
              • T takoo
                1 Feb 2016, 19:19

                yes unfourtunely

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 1 Feb 2016, 19:35 last edited by
                #10

                @takoo
                and you did use something else than "e:/" ?
                and else exact code? Model is living in mainwin .h and dont run out of scope.
                (ps sample leaks view)

                Hmm. I cant guess sorry.

                What Qt version and platform?

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  takoo
                  wrote on 1 Feb 2016, 19:41 last edited by
                  #11

                  QT 5.5 Linux mint

                  Code is here

                  MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                  const QString dir( "/home/tako/cocos2d-x/" );
                     const QString targetDir( dir + "OpenWorld/Classes"  );
                     const QString targetRes(dir+"OpenWorld/Resources");
                     const QString targetBin(dir+"OpenWorld/bin");
                  
                     model = new QFileSystemModel;
                     model->setRootPath( targetDir );
                  
                  
                  
                     filter = new filtermodel( targetDir,targetRes,targetBin);
                     filter->setSourceModel(model);
                     filter->mapToSource(i);
                    ui->treeView->setModel(filter);
                    ui->treeView->setRootIndex(filter->mapFromSource(model->index(dir)));
                  }
                  
                  void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
                  {
                  
                      i=index;
                      qDebug()<<model->fileName(i);
                  
                  }
                  
                  

                  I just write code ------- (-_-) ----------

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 1 Feb 2016, 21:30 last edited by
                    #12

                    Hi,

                    index comes from filter not from model. You have to map the index like you did in your setRootIndex call

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      takoo
                      wrote on 1 Feb 2016, 21:43 last edited by
                      #13

                      Please give me example code .
                      I writting at the moment from phone

                      I just write code ------- (-_-) ----------

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 1 Feb 2016, 21:51 last edited by
                        #14

                        Do you mean an example of calling mapToSource ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          takoo
                          wrote on 1 Feb 2016, 23:16 last edited by
                          #15

                          Codes above

                          I just write code ------- (-_-) ----------

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 2 Feb 2016, 11:45 last edited by
                            #16

                            In the code above, you are trying to use an index from your proxy on your file system model. That's the problem, you have to use mapToSource in order to get the right index.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            1
                            • T Offline
                              T Offline
                              takoo
                              wrote on 2 Feb 2016, 15:20 last edited by takoo 2 Feb 2016, 19:50
                              #17

                              @SGaist Where will I use mapToSource ?

                              I just write code ------- (-_-) ----------

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 2 Feb 2016, 21:31 last edited by
                                #18

                                In on_treeView_doubleClicked

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  takoo
                                  wrote on 3 Feb 2016, 10:51 last edited by
                                  #19

                                  @SGaist I wrote this code and again I get error("the has unexpectedly finished") ```
                                  void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
                                  {

                                  if(index.isValid())
                                  {
                                  filter->mapToSource(model->index(dir));
                                  qDebug()<<model->filePath(index);
                                  }
                                  }

                                  I just write code ------- (-_-) ----------

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 3 Feb 2016, 10:55 last edited by
                                    #20

                                    @takoo said:

                                    Hi
                                    http://doc.qt.io/qt-5.5/qsortfilterproxymodel.html#mapToSource
                                    it returns a new index. I assume you should use that index.
                                    you still use "old" index filePath(index);

                                    QModelIndex mapped=filter->mapToSource(model->index(dir));
                                    model->filePath(mapped);

                                    1 Reply Last reply
                                    0
                                    • T Offline
                                      T Offline
                                      takoo
                                      wrote on 3 Feb 2016, 11:01 last edited by
                                      #21

                                      hi ```

                                      I get error (QSortFilterProxyModel: index from wrong model passed to mapToSource)
                                      void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
                                      {

                                      if(index.isValid())
                                      {
                                      QModelIndex mapped=filter->mapToSource(model->index(dir));

                                          qDebug()<<model->filePath(mapped);
                                       }
                                      

                                      }

                                      I just write code ------- (-_-) ----------

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 3 Feb 2016, 11:01 last edited by
                                        #22

                                        oh
                                        maybe its
                                        mapToSource(index)

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          takoo
                                          wrote on 3 Feb 2016, 11:06 last edited by
                                          #23

                                          Thanks everybody

                                          I just write code ------- (-_-) ----------

                                          1 Reply Last reply
                                          0

                                          13/23

                                          1 Feb 2016, 21:43

                                          • Login

                                          • Login or register to search.
                                          13 out of 23
                                          • First post
                                            13/23
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved