Results 1 to 2 of 2

Thread: ComboBox default value

  1. #1
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default ComboBox default value

    Hi,
    I want to set default value for combobox. But "find" method returns -1.
    Qt Code:
    1. MyComboBox{
    2. id:cmbZoom
    3. model:XmlListModel {
    4. id: xmlZoomModel
    5. source: "files/zoom.XML"
    6. query: "/tbl_zoomCalib/record"
    7. XmlRole { name: "text"; query: "@zoom/string()" }
    8. XmlRole { name: "value"; query: "@number/string()" }
    9. }
    10. textRole: "text"
    11. onCurrentIndexChanged: {
    12. myXML.newZoom=xmlZoomModel.get(currentIndex).text;
    13. }
    14. Component.onCompleted: {
    15. currentIndex=cmbZoom.find("20");
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by neda; 5th April 2016 at 08:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox default value

    You are calling find() when the combo box is completed, which is likely before it has data.
    You probably want to do that when the data has been loaded, see XmlListModel's status property.

    Cheers,
    _

Similar Threads

  1. Color ComboBox
    By ioannis in forum Qt Programming
    Replies: 14
    Last Post: 23rd March 2016, 07:08
  2. how do I use comboBox
    By QT++ in forum Newbie
    Replies: 5
    Last Post: 2nd July 2013, 14:13
  3. Help ComboBox
    By vinny gracindo in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 19:41
  4. ComboBox of bmp:s
    By SailinShoes in forum Qt Programming
    Replies: 2
    Last Post: 5th March 2008, 15:22
  5. Color combobox
    By chguy2 in forum Qt Programming
    Replies: 9
    Last Post: 5th April 2007, 14:23

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.