Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Sorting

  1. #1
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post Sorting

    I have value like

    abc1
    abc2
    abc10
    abc100
    bcd5
    abcd1
    abcd2
    abc3
    zbc1
    xyz1

    how can i sort it so that both text value and numeric value will be sorted. So that i will get the result like:

    abc1
    abc2
    abc3
    abc10
    abc100
    abcd1
    abcd2
    bcd5
    xyz1
    zbc1

    I.e. i want both alpha value and numeric value will be sorted.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sorting

    These situations are not a problem as a simple sort will do this. This becomes a problem:

    abc13
    abc103

    Do you want it sorted this way or the other way (103 first, then 13)?

    Anyway, use qSort() and provide a custom implementation of the LessThan functor
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sorting

    I am using Qsort , but how can i sort, which should be sorted in both alphabetically and numeric value?
    Please send me the code.

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    I am using Qsort , but how can i sort, which should be sorted in both alphabetically and numeric value?
    Read again what Wysota posted:
    use qSort() and provide a custom implementation of the LessThan functor
    Run QtAssistant and read about qSort and QString to get know how to extract numeric part of your string. Probably it could be done easy with QRegExp. Then implement your own LessThan functor.
    Please send me the code.
    Please send me fresh donuts.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Question already answered in full length here:

    http://www.qtcentre.org/threads/2141...930#post130930

    Johannes

  6. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Quote Originally Posted by faldżip View Post
    Please send me fresh donuts.
    LOL! Made my day!

    You are right. That "give me" attitude is hardly the nicest way of asking for help.

    But who knows? Maybe it's just a language barrier?

    Johannes

  7. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Quote Originally Posted by JohannesMunk View Post
    You are right. That "give me" attitude is hardly the nicest way of asking for help.

    But who knows? Maybe it's just a language barrier?
    Maybe but maybe not :P
    If it is just a language barrier then I hope my answer would encourage to find better words than "give me" next time.
    But I think that in many cases it is not only language. Half of the post can be answered by opening QtAssistant, finding required solution and rewriting it in QtCentre forum, sometimes with slightly changed example, just because the guy who started thread don't want to spend 10minutes reading documentation. And with "give me the code" attitude you don't learn anything. I know that because when I was starting to learn programming I wanted to have working code fast and was rewriting, copy-pasting code and then you have to do it every time because you have no idea how your code is working and why it is not working. And I learned programming on my studies but without doing additional exercises (besides those I had to do) at home I would know nothing. And Qt has a really good documentation and it has nice tool out of the box (QtAssistant) to allow you easily get anything you want about Qt classes. Assistant is running almost all the time on my computer so I can check the way I should use the Qt classes at any moment. It's icon is placed next to the web browser icon on my quick launch bar :] And on browser's bookmarks bar there is a cppreference.com button so I can check basic C/C++ functions, classes because it takes much less time then making new thread on forum and waiting for answer...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. #8
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    I agree with you, that copy pasting code without even reading it, doesn't help. But that's up to the reader.

    I generally agree that, if someone asks for a fish its usually better to teach him fishing. But giving him the fish that you fished together, is acceptable too, I think :->

    On the other hand the question here (natural sorting of strings, see the other posts of OP) can not be answered with Qt Assistant. And without knowing the right term not with google either.

    What disturbs me, though, is that because some people exploit this kind of forum as the chance to get everything without any hasle at all and without even saying thanks afterwards, the tone of the answers gets quite rough, sometimes. And that's not a healthy development, I think. Neither for the stress level of regular posters, nor for the forums atmosphere.

    Johannes

  9. #9
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Quote Originally Posted by JohannesMunk View Post
    On the other hand the question here (natural sorting of strings, see the other posts of OP) can not be answered with Qt Assistant. And without knowing the right term not with google either.
    But typing "QString sorting" in search line edit of this forum and pressing enter will give the topic which you linked few posts above, where the solution was discussed and already done. Using compareNames() function in qSort() requires rather C++
    only knowledge. So I almost agree with your one point - no need to use QtAssistant to get the solution, because it is already here.
    Another thing is that what people cannot notice easily is that Qt is a C++ library, not programming language, so you are not programming in Qt, you are programming in C++ with Qt. So the simple implication is that you have to learn C++ to use Qt. And you don't have to know everything about C++, but there is some subset of C++ features which are commonly used and covered by almost every book and tutorial.
    And this is the case here also... The solution is given, now you have to use it regarding C++ syntax (It is even mention how in above linked thread).
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sorting

    Quote Originally Posted by faldżip View Post
    Half of the post can be answered by opening QtAssistant, finding required solution and rewriting it in QtCentre forum
    Half? I'd say "about 90%". The rest just requires some experience.

    Quote Originally Posted by JohannesMunk View Post
    I agree with you, that copy pasting code without even reading it, doesn't help. But that's up to the reader.
    That would be true if he had to pay some money for the solution to the person who provided it. But if answers are free then why bother looking for them yourself if there are people who will do it for you? So I'd say it's really up to the person providing the solution. Next time he/she simply won't bother doing that at all.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Quote Originally Posted by wysota View Post
    That would be true if he had to pay some money for the solution to the person who provided it. But if answers are free then why bother looking for them yourself if there are people who will do it for you?
    What would money change? Would it take away the feeling of being exploited? I think, that can only be cured by an honest "thank you". And some people are kind enough to say it. We should have a law for it, though :->

    Quote Originally Posted by wysota View Post
    So I'd say it's really up to the person providing the solution. Next time he/she simply won't bother doing that at all.
    What somebody does with something you helped him with is entirely his thing. I think that's something fundamental to true help. Think of somebody saving another one's life. He owes him a big thank you. But the saver doesn't own the saved person's life afterwards. Otherwise its not help, but some kind of extortion in disguise.

    With helping the situation is always a little pre-loaded.. Because as helper you do expect some kind of gratitude. If that gratitude fails your expectations or is replaced by bold demands, trouble is underway. I don't have a solution for that. I just tend to avoid those people afterwards. And try to keep my hopes up, that the next person will not fail me.

    Good night!

    Johannes

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sorting

    Quote Originally Posted by JohannesMunk View Post
    What would money change? Would it take away the feeling of being exploited?
    It's the other way round. You'd ask questions more carefully and try doing something yourself first if you had to pay (even a small fee) for each answer you get.

    What somebody does with something you helped him with is entirely his thing.
    Oh, no argument here. Of course provided he doesn't violate any licence.

    I think that's something fundamental to true help. Think of somebody saving another one's life. He owes him a big thank you. But the saver doesn't own the saved person's life afterwards. Otherwise its not help, but some kind of extortion in disguise.
    Would you jump from a cliff if you knew someone would save you? Would you jump if you didn't know if someone would be there to save you?

    Of course you can also look at things from the other person's perspective: If someone would be jumping off the cliff all the time, wouldn't you grow tired of saving him constantly and telling him not to do it again?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Damn.. now I wrote for 15minutes.. and pressed the wrong button. Everything lost.. Happened to me twice today. Can't the "+Reply to Thread" Button be disabled, when using the Quick Reply box?

    I'll answer again tomorrow!

    Johannes

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sorting

    Happened to me too If you're using Firefox, install the "Lazarus" extension.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sorting

    An easy solution is not to use the quick reply box I always click "Go advanced" to take care of this. I've been bitten before.

  16. #16
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Thanks for sharing your button experiences :-> I have installed Lazarus. And for the longer replies I'll use the advanced mode from now on :-> But back to our discussion!

    Quote Originally Posted by wysota View Post
    It's the other way round. You'd ask questions more carefully and try doing something yourself first if you had to pay (even a small fee) for each answer you get.
    I see your point! But that could also be solved by reputation. If each question/thread got a "laziness"-rating, where you could pursue your frustration when answering, and each profile would show an average laziness value of the threads started, maybe that could bring some lazy-posters down. As the thanks button boosts helping..

    Quote Originally Posted by wysota View Post
    Would you jump from a cliff if you knew someone would save you? Would you jump if you didn't know if someone would be there to save you?
    Good imagery! I would not. Both times. I'm not suicidal :-> Speaking of saving a life was maybe a bit to drastic of me. Because I don't think that a lot of people around here, start there projects, planning to rely on external (free) support. It's maybe more like getting a little lost underway. And you can either stumble around on your own for some time, or you can ask the nice lady in the shop for directions.

    Quote Originally Posted by wysota View Post
    Of course you can also look at things from the other person's perspective: If someone would be jumping off the cliff all the time, wouldn't you grow tired of saving him constantly and telling him not to do it again?
    Well if the same person got lost all the time, and each time demanded that I drove him home, I would give up after some time, sure. That's whats happening here I think. But the problem is that there are so many people, getting lost a bit. And each one of them deserves a fresh start! Without being ranted at. And thats the problem with a bad atmosphere: Its quite undirected..

    What do you think? Would a laziness value help?

    Johannes

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sorting

    We already have a reputation scoring system here. You can click the star icon under each post and modify the author's reputation rating. Try it
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    Allright. But there is no public consequence. Where is the reputation rating visible for every one else?

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sorting

    Quote Originally Posted by JohannesMunk View Post
    But there is no public consequence.
    There will be once people start using the system. For example we'll disable posting in any forums but the newbie forum for people with low reputation.

    Where is the reputation rating visible for every one else?
    The green rectangle under a user name and user title in each of the posts marks the reputation. Hovering over it will give a more elaborate description. You can compare your reputation, mine and that of franco.ammato - they will differ.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting

    This is great! Why don't you make a sticky explaining all of this in detail? Because I looked for news of the site itself.. wanted to read about the new design, but couldn't find anything.

    How are the comments on the post going to be used? Just as a note to the poster? Or visible for the public? How should they be phrased? What levels of reputation are there?

    Johannes

Similar Threads

  1. Sorting a qLinkedList
    By pwaldron in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2010, 21:59
  2. QTableWidget sorting
    By losiem in forum Qt Programming
    Replies: 4
    Last Post: 14th July 2008, 20:20
  3. QListView sorting
    By fear in forum Qt Programming
    Replies: 14
    Last Post: 21st August 2007, 13:08
  4. Sorting a QVector
    By jiveaxe in forum Qt Programming
    Replies: 21
    Last Post: 11th August 2007, 19:24
  5. Sorting in QTreeWidget
    By adhit in forum Qt Programming
    Replies: 15
    Last Post: 8th May 2007, 12:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.