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"
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeviewqfilesystemmodedoubleclick
23 Posts 3 Posters 12.9k 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 Offline
    T Offline
    takoo
    wrote on last edited by takoo
    #1

    I get this error when double clicked of qtreeview item "The program unexpectedly finished"

    not get error when I writing "qDebug()<<model.fileName(index);"
    I get error when only writting filePath.
    How can I solve ?

    void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
    {
        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 mrjj
      #2

      @takoo said:
      Hi and welcome
      Is the model a QDirModel ?
      are you doing something like
      http://www.bogotobogo.com/Qt/Qt5_QTreeView_QDirModel_ModelView_MVC.php

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

        my model a QFileSystemModel.

        This problem not relevant your example :(

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

        mrjjM 1 Reply Last reply
        0
        • T takoo

          my model a QFileSystemModel.

          This problem not relevant your example :(

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

            I am using QSortFilterProxyModel for filtering

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

            mrjjM 1 Reply Last reply
            0
            • T takoo

              I am using QSortFilterProxyModel for filtering

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

                i tryed but was not . I get same error .

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

                mrjjM 1 Reply Last reply
                0
                • T takoo

                  i tryed but was not . I get same error .

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

                    yes unfourtunely

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

                    mrjjM 1 Reply Last reply
                    0
                    • 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

                                          • Login

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