Results 1 to 11 of 11

Thread: Idea for sorting values from QLineEdits?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Idea for sorting values from QLineEdits?

    You are sorting the list, but you don't use it anymore later. Just display the numbers from this list to line edits, using a for loop like high_flyer suggested. You can use QString::number() method, no need for temporary QString objects here.
    I'll give you some hints about the "for" loop:
    Qt Code:
    1. QList<double> list;
    2. for( /*something*/ {
    3. double number = ...
    4. list << number;
    5. }
    6. qSort(list.begin(), list.end(), qGreater<double>());
    7. // and display:
    8. for( /*something*/ ){
    9. in[/*?*/]->setText( QString::number(/*??*/) );
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to stampede for this useful post:

    ewwen (25th May 2011)

  3. #2
    Join Date
    May 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Idea for sorting values from QLineEdits?

    Hi, thanks for your reply!

    Well even if I fill, it doesn´t work.
    Qt Code:
    1. QList<double> list;
    2. for(int i = 0; i < Num; ++i) {
    3. double number[i] = in[i]->text().toDouble(&ok);
    4. list << number[0] << number[1] << number[2] << number[3] << number[4];
    5. }
    6.  
    7. qSort(list.begin(), list.end(), qGreater<double>());
    8. for(int i = 0; i < Num; ++i){
    9. in[i]->setText( QString::number());
    10. }
    To copy to clipboard, switch view to plain text mode 

    I don´t get the values, which I want to display in in[i] again after sorting.

    This works better:
    Qt Code:
    1. QList<double> list;
    2. bool ok;
    3. double number1 = in[0]->text().toDouble(&ok);
    4. double number2 = in[1]->text().toDouble(&ok);
    5. double number3 = in[2]->text().toDouble(&ok);
    6. double number4 = in[3]->text().toDouble(&ok);
    7. double number5 = in[4]->text().toDouble(&ok);
    8. list << number1 << number2 << number3 << number4 << number5;
    9.  
    10. qSort(list.begin(), list.end(), qGreater<double>());
    To copy to clipboard, switch view to plain text mode 
    but there I still have the problem to display the ordered values...

    Can anyone give me an advice, where to search or what to consider? (I tried several attempts now, but no one worked)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Idea for sorting values from QLineEdits?

    You are confusing all kinds of stuff, and you clearly have no understanding of how basic variable deceleration works.
    You should really first learn basic programming concepts, and C syntax before you start programming with C++ and Qt.

    your original code could not even compile!

    Qt Code:
    1. QList<double> list;
    2. for(int i = 0; i < Num; ++i) {
    3. list << in[i]->text().toDouble(&ok);
    4. }
    5.  
    6. qSort(list.begin(), list.end(), qGreater<double>());
    7. for(int i = 0; i < Num; ++i){
    8. in[i]->setText( QString::number(list.at(i)));
    9. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. The following user says thank you to high_flyer for this useful post:

    ewwen (25th May 2011)

  6. #4
    Join Date
    May 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Idea for sorting values from QLineEdits?

    Hi high_flyer, thanks for your help! Now everything runs and I finally understood the problem...

    I´m still learning to programme and not everything I try, I find in books or tutorials. You are a professional and I am a beginner.

  7. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Idea for sorting values from QLineEdits?

    ewwen, that is ok to learn, everyone was a beginner once.
    But you are tackling Qt, which prerequisites C++ knowledge, where as you are still in your first steps with C/C++ syntax and principals, thus doing anything with Qt will only make it more difficult.
    You should first concentrate on C/C++, and once you are comfortable with the language and basic concepts, you will find Qt very helpful.
    Otherwise you will find Qt hard confusing and frustrating.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 2
    Last Post: 21st December 2010, 20:43
  2. A Hippie Idea
    By qtoptus in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2010, 23:28
  3. Replies: 4
    Last Post: 27th August 2010, 10:27
  4. ???any one have idea about this ???
    By damodharan in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2010, 09:08
  5. UI Idea please
    By munna in forum General Discussion
    Replies: 1
    Last Post: 9th May 2006, 11:14

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
  •  
Qt is a trademark of The Qt Company.