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] std::sort on QList<QPushButton*> doesn't work
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] std::sort on QList<QPushButton*> doesn't work

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.4k Views 1 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.
  • N Offline
    N Offline
    nologinma
    wrote on last edited by
    #1

    My code is the following:

    I have declare

    @QList<QPushButton*> *local; @

    and I use it in the following mode:

    @std::sort(local->begin(), local->end(), pushButtonLessThan );@

    and after I declare:

    @bool MainWindow::pushButtonLessThan(QPushButton v1, QPushButton v2)
    {
    QRect myrect1;
    QRect myrect2;

    myrect1 = v1.geometry();
    myrect2 = v2.geometry();
    
    if (myrect1.left() < myrect2.left()) return true;
    else return false;
    

    }@

    When I compile I have the following error:

    @........\android\androidNDK\sources\cxx-stl\gnu-libstdc++\4.8\include/bits/stl_algo.h:5474:5: note: void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = QList<QPushButton*>::iterator; _Compare = bool (MainWindow::)(QPushButton, QPushButton)]
    sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
    ^
    ........\android\androidNDK\sources\cxx-stl\gnu-libstdc++\4.8\include/bits/stl_algo.h:5474:5: note: no known conversion for argument 3 from '<unresolved overloaded function type>' to 'bool (MainWindow::
    )(QPushButton, QPushButton)'@

    Where is the problem ?

    Please can you help me?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You need the method to be static, and you have to make it accept QPushButton pointers. Right now you are trying to sort a list of pointers using a sorting function that does not take in pointers.

      (Z(:^

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nologinma
        wrote on last edited by
        #3

        Thanks, now it work.

        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