Results 1 to 6 of 6

Thread: How to get comboBox data instead of index with registerfield

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to get comboBox data instead of index with registerfield

    Hi,

    I'm making a GUI app with a QWizard and QWizardPages structure.

    In the first page I have a combobox (cb_info1) with some items:
    Qt Code:
    1. cb_info->AddItem("A");
    2. cb_info->AddItem("B");
    3. cb_info->AddItem("C");
    To copy to clipboard, switch view to plain text mode 

    Then I register it using: registerField("Info_combo", cb_info);

    And finally in page2, I want to show which option was selected(if A, B or C) showing the info on a label:

    Qt Code:
    1. myLabel->setText(field("Info_combo").toString());
    To copy to clipboard, switch view to plain text mode 


    If option A was selected, myLabel should show (or at least is want I am trying to): A
    But instead of that it shows '0' which I suppose its the index of the item selected of the Combobox.

    How can I make that the label shows "A" instead of the index ?

    Thank you.

  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: How to get comboBox data instead of index with registerfield

    Look at the documentation of registerField:
    for a QComboBox the default property is currentIndex.

    Look at the properties of QComboBox and at the third argument of registerField.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to get comboBox data instead of index with registerfield

    You can get the current item's text in a QComboBox with currentText();
    Last edited by adutzu89; 2nd February 2015 at 14:08.

  4. #4
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get comboBox data instead of index with registerfield

    Look at the documentation of registerField:
    for a QComboBox the default property is currentIndex.

    Look at the properties of QComboBox and at the third argument of registerField.
    That is something I've already tried but I just get errors cause I don't know how to put it really... I'm trying with registerField("Info_combo", cb_info, cb_info->currentText()) but there is no way to make it work

    You can get the current item's text in a QComboBox with currentText();
    Yes I know, but with that you need to pass the index and I want it throw registerField() property But can't find the way

  5. #5
    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: How to get comboBox data instead of index with registerfield

    Quote Originally Posted by roseicollis View Post
    That is something I've already tried but I just get errors cause I don't know how to put it really... I'm trying with registerField("Info_combo", cb_info, cb_info->currentText()) but there is no way to make it work
    Look at the documentation more closely.
    You will find that its method documentation, like the one for registerField(), has information about the type of each argument.

    In the case of registerField's third argument it is "const char*", which, as you a C++ developer will know, is the type of C string literal.
    Which, as you know, is a sequence of characters within double quotes.

    Looking again at the documentation, you will find that each QObject based class has a section describing its properties.

    Cheers,
    _

  6. #6
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get comboBox data instead of index with registerfield

    Oh! I see what you mean now. Didn't notice about that, Thanks!

Similar Threads

  1. Replies: 2
    Last Post: 24th August 2013, 14:52
  2. recuperate index item selected in comboBox
    By johan07 in forum Newbie
    Replies: 6
    Last Post: 26th December 2012, 19:52
  3. How to get index of a combobox delegate selection
    By vieraci in forum Qt Programming
    Replies: 12
    Last Post: 21st July 2009, 17:37
  4. ComboBox Completer Index Problem
    By majatu in forum Qt Programming
    Replies: 3
    Last Post: 7th June 2009, 15:30
  5. NUll character output for combobox index
    By mdskpr778 in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 19:22

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.