Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. sort

    Log in to post
    • All categories
    • M

      Unsolved QVector of QPair<int, QString> does not sort the elements C++
      General and Desktop • qpair qvector sort algorithms c++ • • MEsc

      2
      0
      Votes
      2
      Posts
      181
      Views

      Christian Ehrlicher

      No sort problem but a basic c(++) problem - you pass the parameters to unzip() by value instead by reference so how should the those variables be updated outside?

    • M

      Unsolved sort a vector and shuffle all similar values
      General and Desktop • shuffle vector qvector c++ sort • • MEsc

      4
      0
      Votes
      4
      Posts
      200
      Views

      Chris Kawa

      There are examples and detailed descriptions on both pages I linked.

    • M

      Unsolved resorting ONE value in a sorted vector
      General and Desktop • qvector algorithms sort int qstring • • MEsc

      10
      0
      Votes
      10
      Posts
      387
      Views

      Chris Kawa

      Btw. to put my money where my mouth is this is my proposal for this problem. Yes, I'm assuming the format is fixed and search operations won't return -1. If that isn't the case you can add one if to range check the indices.

      std::ranges::sort(vec, [](QStringView a, QStringView b) { int pos_a = a.lastIndexOf(' '); int pos_b = b.lastIndexOf(' '); int int_a = a.sliced(pos_a).toInt(); int int_b = b.sliced(pos_b).toInt(); return int_a < int_b; });

      Do you consider this unreadable? And no, this is not fully optimized either, because it does the same int conversions multiple times, but I consider something like this to be a "good enough starting point" and in-depth optimization is possible if need arises e.g. by caching the conversions or changing the data structure.

      EDIT Just after posting I realized you can do the QStringView creation right in the params, so even simpler.

    • CybeX

      Unsolved (valid) QFileInfo causes segv when calling QFileInfo::filename() in std::sort
      General and Desktop • qt5 qt5.13.1 qfileinfo std sort • • CybeX

      2
      0
      Votes
      2
      Posts
      205
      Views

      JonB

      @CybeX
      Well, the debugger shows a as "<not accessible>", so unless its value has been optimized out that seems to be the cause of the SEGV. I admit I don't know how/why, assuming you only put items into fileInfoImageList via the code you show.

      I would start by just checking you can visit/print out all the QFileInfos in your lists before you start the std::sort()?

      I would also force a complete rebuild just to make sure. The placement of the debug breakpoint on line #319 which is blank looks odd to me, it's not supposed to do that....

    • J

      Solved Detecting sort completed on QTableWidget
      General and Desktop • qt 5 qtablewidget sort • • james b-s

      7
      0
      Votes
      7
      Posts
      673
      Views

      J

      Thanks that worked

    • O

      Solved Implement QSortFilterProxyModel with own TreeModel?
      General and Desktop • qsortfilterprox treemodel treeview sort • • Opa114

      11
      0
      Votes
      11
      Posts
      2028
      Views

      O

      @VRonin said in Implement QSortFilterProxyModel with own TreeModel?:

      Good guess, can you show us your code?

      I solved it: I had to pass the parent index (tree structure), so the line should look like this:

      QVariant data = m_proxy->data(m_proxy->index(index.row(), 4, index.parent()));
    • C

      Unsolved Sorting with ignored items
      General and Desktop • sort models • • Craetor

      5
      0
      Votes
      5
      Posts
      898
      Views

      C

      @JonB, thanks, i will try your implementation.

    • K

      Solved Sorting QTableview items alphabetically!
      General and Desktop • tableviewcolumn items sort alphabetical • • Kushan

      6
      0
      Votes
      6
      Posts
      3687
      Views

      K

      @VRonin Thanx mate

    • K

      Unsolved What class of Proxy Model should I pick in the case?
      General and Desktop • qsortfilterprox models sort mapping filter • • Kofr

      4
      0
      Votes
      4
      Posts
      1335
      Views

      raven-worx

      @Kofr
      mapFromSource() and mapToSource() are enough. The default implementation should depend on these methods only.

    • JulienLopez

      Unsolved selection update on model sorting/re-ordering with Qt
      General and Desktop • mvc proxy model sort selection • • JulienLopez

      3
      0
      Votes
      3
      Posts
      1324
      Views

      JulienLopez

      Yeah but the user also want to be able to reorder things as he wants, not just sort (ie, put this row here, drag all my selection at this position, invert these two rows, ...)

    • Donn

      Unsolved Sort numeric files in Windows
      General and Desktop • sort numeric files windows qdir • • Donn

      3
      0
      Votes
      3
      Posts
      1282
      Views

      Donn

      Is QCollator::compare a good option for this? I mean, I simply implement a sorting algorithm based on the result from QCollator::compare. Usually the number of files will be limited to ~3000.

    • M

      QTreeWidget multiple sorts
      General and Desktop • qtreewidget sort • • Mailchuck

      2
      0
      Votes
      2
      Posts
      1194
      Views

      M

      I figured it out, that information is the header of the QTreeWidget. So, the code to extract this value from within a QTreeWidgetItem is:

      self.treeWidget().header().sortIndicatorOrder()

      and this you can check for being equal to Qt.DescendingOrder (or Qt.AscendingOrder if you prefer).