Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]QSortFilterProxyModel Crashes
Qt 6.11 is out! See what's new in the release blog

[Solved]QSortFilterProxyModel Crashes

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 12.8k Views 3 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    You should run your application through the debugger, it will show you the exact point of crash.

    Note that you are doing something wrong: you are trying to emit a signal from another class.

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

    ? 2 Replies Last reply
    0
    • SGaistS SGaist

      Hi,

      You should run your application through the debugger, it will show you the exact point of crash.

      Note that you are doing something wrong: you are trying to emit a signal from another class.

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #3

      @SGaist
      Depends on mouse click cell first or show/hide column first, I got this two stack.
      And disassember shows, don't know how to show code yet.
      And here is the project if anyone could try it.
      Tested with (Qt 5.3 linux, qt5.5 linux, qt5.5 windows)
      Sometimes crash on parent();
      0 QSortFilterProxyModel::parent(QModelIndex const&) const 0x7ffff70f9ced
      1 QPersistentModelIndex::parent() const 0x7ffff70d8d73

      Sometimes crash on here,
      0 QSortFilterProxyModelPrivate::index_to_iterator D:/Qt/5.5/mingw492_32/bin/Qt5Cored.dll 187 0x114d743
      1 QSortFilterProxyModelPrivate::proxy_to_source D:/Qt/5.5/mingw492_32/bin/Qt5Cored.dll 376 0xfb3536
      2 QSortFilterProxyModel::mapToSource D:/Qt/5.5/mingw492_32/bin/Qt5Cored.dll 2718 0xfbab5f
      3 QSortFilterProxyModel::flags D:/Qt/5.5/mingw492_32/bin/Qt5Cored.dll 2200 0xfb9ae1

      1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should run your application through the debugger, it will show you the exact point of crash.

        Note that you are doing something wrong: you are trying to emit a signal from another class.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #4

        @SGaist
        Found a work around.
        Clear proxy model first, then set source model again.

            _proxyModel->clear();
            _proxyModel->setIsMaxMinShown(!_proxyModel->isMaxMinShown());
            _proxyModel->setSourceModel(_vm);
            emit _vm->layoutChanged(); // change this to emit from vm class.
        
        
        ? 1 Reply Last reply
        0
        • ? A Former User

          @SGaist
          Found a work around.
          Clear proxy model first, then set source model again.

              _proxyModel->clear();
              _proxyModel->setIsMaxMinShown(!_proxyModel->isMaxMinShown());
              _proxyModel->setSourceModel(_vm);
              emit _vm->layoutChanged(); // change this to emit from vm class.
          
          
          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #5

          @sharethl
          Clear and set source model again still have chances to crash.....

          ? 1 Reply Last reply
          0
          • ? A Former User

            @sharethl
            Clear and set source model again still have chances to crash.....

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #6

            @sharethl
            Remove this line working
            emit _vm->layoutChanged(); // change this to emit from vm class.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              karlheinzreichel
              wrote on last edited by
              #7

              to update your table, you better use
              emit dataChanged(modelIndexFrom, modelIndexTo);

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Are you sure _vm is not null ? And again, don't call emit on other classes like that, it feels like your doing some bad design.

                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
                • K Offline
                  K Offline
                  karlheinzreichel
                  wrote on last edited by
                  #9

                  You have to emit layoutAboutToBeChanged() before you change your model
                  and emit layoutChanged after your model changes to reflect the changes to the ui
                  (see documentation void QAbstractItemModel::layoutChanged())

                  some code

                  void MainWindow::on_pushButton_clicked()
                  {
                     _vm->tellLayoutAboutToBeChanged();
                      _proxyModel->setIsMaxMinShown(!_proxyModel->isMaxMinShown());
                      _vm->tellLayoutChanged();
                  }
                  
                  void Vm::tellLayoutChanged()
                  {
                     emit layoutChanged();
                  }
                  
                  void Vm::tellLayoutAboutToBeChanged()
                  {
                     emit layoutAboutToBeChanged();
                  }
                  
                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    That design is completely wrong. It's the responsibility of the model to know when to emit anything. The proxy will make the signals follow. It's not the role of MainWindow at all to call these functions.

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

                    K 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Are you sure _vm is not null ? And again, don't call emit on other classes like that, it feels like your doing some bad design.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #11

                      @SGaist Yes, bad design, will correct this.

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        That design is completely wrong. It's the responsibility of the model to know when to emit anything. The proxy will make the signals follow. It's not the role of MainWindow at all to call these functions.

                        K Offline
                        K Offline
                        karlheinzreichel
                        wrote on last edited by
                        #12

                        @SGaist
                        You are absolutely right.
                        But the question was for the reason the application crashes.

                        The reason for the crash is not the architecture but the missing layoutAboutToBeChanged()

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          Still, that call is not done at the right place, so you're currently just lucky it works.

                          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

                          • Login

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