Results 1 to 6 of 6

Thread: problem with comboBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question problem with comboBox

    hi every body

    i am facing problem with the combo Box ... i want to change its current value on text edite at line Edit ... so i used this slot :

    Qt Code:
    1. void CheckoutDialog::on_empNoEdit_textChanged(QString number)
    2. {
    3.  
    4. int i=query.record().indexOf(number);
    5.  
    6.  
    7. ui->empNameBox->setCurrentIndex(i);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 


    at execute the combo box do nothing

    could any one tel me what i am missing ?

    great thanx

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem with comboBox

    Ehm, what is what??? make sure i is set to the right value, and is query valid in your slot? and is it called after all?

  3. #3
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with comboBox

    i changed the code theory to this one and its worked fine :


    Qt Code:
    1. void CheckoutDialog::on_empNoEdit_textChanged()
    2. {
    3.  
    4. int k=1;
    5.  
    6. query.first();
    7.  
    8. //_______check for item(0)____________
    9. if (ui->empNoLine->text().toInt()==query.value(0).toInt())
    10.  
    11. {
    12. ui->empNameBox->setCurrentIndex(k);
    13.  
    14.  
    15. }
    16. //_____________________________________
    17.  
    18.  
    19. //_______for the rest of items___________
    20.  
    21. while(query.next())
    22.  
    23. {
    24.  
    25.  
    26. if (ui->empNoLine->text().toInt()==query.value(0).toInt())
    27.  
    28. {
    29. ui->empNameBox->setCurrentIndex(k);
    30.  
    31. break;
    32. }
    33.  
    34.  
    35. k++;
    36. }
    37. //_________________________________________
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 


    is there any way to do this in a simple way ?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem with comboBox

    Quote Originally Posted by tinysoft View Post
    is there any way to do this in a simple way ?
    Yes, surely! But You still haven't said what the content of query is, what in your combo box is displayed etc...

    One (of some) improvements: use a do-while scope. (or for loop) So you can integrate the check of the first item

  5. #5
    Join Date
    Apr 2010
    Location
    Sudan
    Posts
    46
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with comboBox

    the query is containing numbers of employees , the combo box containing there names, so i sorted the query by the names alphabet like this :

    Qt Code:
    1. query.exec("select emp_no from employees order by name;");
    To copy to clipboard, switch view to plain text mode 

    i want to synchronize the line Edit with the combo box so when user enter number to the line edit , i should get the index of that number on the query and send the index to the combo box to be its current index number.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem with comboBox

    Instead of alway query the database set the id direct as user data to your combo box. then simply loop through the box and check there. Or if it is a long combo box create a local index hash.

  7. The following user says thank you to Lykurg for this useful post:

    tinysoft (3rd May 2010)

Similar Threads

  1. ComboBox Completer Index Problem
    By majatu in forum Qt Programming
    Replies: 3
    Last Post: 7th June 2009, 14:30
  2. Combobox style problem
    By zgulser in forum Qt Tools
    Replies: 5
    Last Post: 13th March 2009, 09:01
  3. [Qt 4.3.1]A problem with combobox style
    By Tamara in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2007, 10:49
  4. color comboBox problem
    By chguy2 in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2007, 09:57
  5. Problem with a combobox
    By Tindor in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2006, 19:18

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.