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]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 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 Extensions
                      • Unsolved