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. The program will easily break down if I use QSortFilterProxyModel to help sort
Qt 6.11 is out! See what's new in the release blog

The program will easily break down if I use QSortFilterProxyModel to help sort

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 6.2k Views 2 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.
  • U uuutty

    @jsulm I give the description in the above, I think full code is unneccessary because I only the proShowInfoList is used in data function.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #8

    @uuutty You wrote: "the program will crash after some seconds". You have a timer with 3 seconds time-out which calls timerUpDate(). Don't you think it could be something there?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    U 1 Reply Last reply
    0
    • jsulmJ jsulm

      @uuutty You wrote: "the program will crash after some seconds". You have a timer with 3 seconds time-out which calls timerUpDate(). Don't you think it could be something there?

      U Offline
      U Offline
      uuutty
      wrote on last edited by
      #9

      @jsulm Maybe I didn't describe my question clearly. If I didn't use QSortFilterProxyModel to help sort and just use my own ProSIModel with same timerUpDate function. , the program will be fine.

      jsulmJ 1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #10

        @uuutty Run your program in a debugger. When it crashes, show us your stack trace.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        2
        • U uuutty

          @jsulm Maybe I didn't describe my question clearly. If I didn't use QSortFilterProxyModel to help sort and just use my own ProSIModel with same timerUpDate function. , the program will be fine.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #11

          @uuutty In timerUpDate you're modifying proShowInfoList and in data() you're accessing proShowInfoList using [] - most probably that's the problem (row does not exist in the list: proShowInfoList[row]). You need to check whether row < proShowInfoList.size().

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          U 1 Reply Last reply
          0
          • jsulmJ jsulm

            @uuutty In timerUpDate you're modifying proShowInfoList and in data() you're accessing proShowInfoList using [] - most probably that's the problem (row does not exist in the list: proShowInfoList[row]). You need to check whether row < proShowInfoList.size().

            U Offline
            U Offline
            uuutty
            wrote on last edited by
            #12

            @jsulm I add

            if (row >= proShowInfoList.length())
                {
                    return QVariant();
                }
            

            into my my function but the problem still exists. Even thoughI do nothing, directly return from my data function.

            @JKSH 0_1487831980283_upload-d41fb452-2221-4354-abf8-2ba82902318e

            Is this what you want?

            JKSHJ 1 Reply Last reply
            0
            • U uuutty

              @jsulm I add

              if (row >= proShowInfoList.length())
                  {
                      return QVariant();
                  }
              

              into my my function but the problem still exists. Even thoughI do nothing, directly return from my data function.

              @JKSH 0_1487831980283_upload-d41fb452-2221-4354-abf8-2ba82902318e

              Is this what you want?

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #13

              @uuutty said in The program will easily break down if I use QSortFilterProxyModel to help sort:

              @JKSH ...
              Is this what you want?

              Yep, that's the stack trace. Unfortunately, we cannot see the full names in the "Function" column.

              Generate that stack trace again, and then Right-Click -> "Copy Contents to Clipboard", and then paste the text here (you don't need to post a picture)

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              U 1 Reply Last reply
              0
              • JKSHJ JKSH

                @uuutty said in The program will easily break down if I use QSortFilterProxyModel to help sort:

                @JKSH ...
                Is this what you want?

                Yep, that's the stack trace. Unfortunately, we cannot see the full names in the "Function" column.

                Generate that stack trace again, and then Right-Click -> "Copy Contents to Clipboard", and then paste the text here (you don't need to post a picture)

                U Offline
                U Offline
                uuutty
                wrote on last edited by
                #14

                @JKSH

                0	QSortFilterProxyModel::parent(QModelIndex const&) const			0xb6e67fe6	
                1	QPersistentModelIndex::parent() const			0xb6e3c298	
                2	??			0xb6e55970	
                3	QItemSelection::merge(QItemSelection const&, QFlags<QItemSelectionModel::SelectionFlag>)			0xb6e4fb76	
                4	QItemSelectionModel::columnIntersectsSelection(int, QModelIndex const&) const			0xb6e505c4	
                5	??			0xb7ba26be	
                6	QHeaderView::paintSection(QPainter *, QRect const&, int) const			0xb7ba144e	
                7	QHeaderView::paintEvent(QPaintEvent *)			0xb7b9a86b	
                8	QWidget::event(QEvent *)			0xb7953e7a	
                9	QFrame::event(QEvent *)			0xb7a5ebda	
                10	QAbstractScrollArea::viewportEvent(QEvent *)			0xb7aec252	
                11	QAbstractItemView::viewportEvent(QEvent *)			0xb7b928f0	
                12	QHeaderView::viewportEvent(QEvent *)			0xb7ba0b3a	
                13	??			0xb7aecd43	
                14	QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject *, QEvent *)			0xb6e9a55f	
                15	QApplicationPrivate::notify_helper(QObject *, QEvent *)			0xb790def8	
                16	QApplication::notify(QObject *, QEvent *)			0xb7913464	
                17	QCoreApplication::notifyInternal(QObject *, QEvent *)			0xb6e9a787	
                18	QWidgetPrivate::sendPaintEvent(QRegion const&)			0xb794c5e6	
                19	QWidgetPrivate::drawWidget(QPaintDevice *, QRegion const&, QPoint const&, int, QPainter *, QWidgetBackingStore *)			0xb794cc3d	
                20	??			0xb791ba9d	
                21	??			0xb791bee6	
                22	QWidgetPrivate::syncBackingStore()			0xb793d9c1	
                23	QWidget::event(QEvent *)			0xb7953ebc	
                24	QMainWindow::event(QEvent *)			0xb7a7689f	
                25	QApplicationPrivate::notify_helper(QObject *, QEvent *)			0xb790df1a	
                26	QApplication::notify(QObject *, QEvent *)			0xb7913464	
                27	QCoreApplication::notifyInternal(QObject *, QEvent *)			0xb6e9a787	
                28	QCoreApplicationPrivate::sendPostedEvents(QObject *, int, QThreadData *)			0xb6e9cc1d	
                29	QCoreApplication::sendPostedEvents(QObject *, int)			0xb6e9d2f7	
                30	??			0xb6ef19b3	
                31	g_main_context_dispatch			0xb668fe29	
                32	??			0xb66900c9	
                33	g_main_context_iteration			0xb6690194	
                34	QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)			0xb6ef1da4	
                35	??			0xb446ce21	
                36	QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)			0xb6e97d13	
                37	QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)			0xb6e9818a	
                38	QCoreApplication::exec()			0xb6ea028a	
                39	QGuiApplication::exec()			0xb722ba81	
                40	QApplication::exec()			0xb7909ab4	
                41	main	main.cpp	20	0x8052880	
                
                
                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #15

                  since you reset the model inside timerUpDate you need to signal the operation with beginResetModel() and endResetModel() http://doc.qt.io/qt-5/qabstractitemmodel.html#beginResetModel

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  U 1 Reply Last reply
                  3
                  • VRoninV VRonin

                    since you reset the model inside timerUpDate you need to signal the operation with beginResetModel() and endResetModel() http://doc.qt.io/qt-5/qabstractitemmodel.html#beginResetModel

                    U Offline
                    U Offline
                    uuutty
                    wrote on last edited by
                    #16

                    @VRonin Thanks a lot! Does this like a semaphore in something need mutual exclusion?

                    VRoninV 1 Reply Last reply
                    0
                    • U uuutty

                      @VRonin Thanks a lot! Does this like a semaphore in something need mutual exclusion?

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #17

                      @uuutty I don't think I get your question... are you multi threading at the model level?

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      U 2 Replies Last reply
                      0
                      • VRoninV VRonin

                        @uuutty I don't think I get your question... are you multi threading at the model level?

                        U Offline
                        U Offline
                        uuutty
                        wrote on last edited by
                        #18

                        @VRonin I probably use the incorrect word. I mean do the beginResetModel() and endResetModel() help to prevent QSortFilterProxyModel or view read from proShowInfoList when I change it.

                        1 Reply Last reply
                        0
                        • VRoninV VRonin

                          @uuutty I don't think I get your question... are you multi threading at the model level?

                          U Offline
                          U Offline
                          uuutty
                          wrote on last edited by
                          #19

                          @VRonin By the way, how can I mark you answer as a correct answer, I find I can just mark my post as a correct answer.

                          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