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

    yes unfourtunely

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on 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 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
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 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 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
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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 last edited by
              #15

              Codes above

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

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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 last edited by takoo
                  #17

                  @SGaist Where will I use mapToSource ?

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

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 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 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
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 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 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
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #22

                            oh
                            maybe its
                            mapToSource(index)

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              takoo
                              wrote on last edited by
                              #23

                              Thanks everybody

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

                              1 Reply Last reply
                              0

                              • Login

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