Results 1 to 8 of 8

Thread: comboBox signal question?

  1. #1
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default comboBox signal question?

    i can't understand how to connect signal slots of comboBox.If it was just a pushButton everything is clear but comboBox consists of
    different choices for example:

    Cars
    Bus
    Truck

    how to implement that different slot to be called if Cars is selected and different if Bus....?

  2. #2
    Join Date
    Feb 2010
    Location
    Finland
    Posts
    7
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: comboBox signal question?

    Maeby you don't need to... What if you connect QComboBox class signal currentIndexChanged ( const QString & text ) to slot where you use switch:
    Qt Code:
    1. connect(combo,SIGNAL(QString &),this,SLOT(makesomething(QString &)));
    2.  
    3. void myClass::makesomething(QString selection){
    4. switch(selection){
    5.  
    6. case...
    7.  
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by viheaho; 21st March 2010 at 20:27.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: comboBox signal question?

    There is no such distinction since you don't need to.

    You could emit a custom signal inside your "activated" signals slot in order to handle if the pressed item is a Bus.

  4. #4
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: comboBox signal question?

    What i do is:

    connect(ui->comboBox, SIGNAL(currentIndexChanged()), this, SLOT(combochanged()));

    void Rechnik::combochanged(int index)
    {
    switch (index) {
    case 0:
    select_dictionary1();
    break;
    case 1:
    select_dictionary2();
    break;
    case 2:
    select_dictionary3();
    break;
    }

    it compiles without errors but nothing happens when i changed comboBox

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

    Default Re: comboBox signal question?

    Check the output window - there will be an error there for you.

    Also, check the documentation - currentIndexChanged() doesn't exist. It's currentIndexChanged(int)

  6. #6
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: comboBox signal question?

    When i put some integer inside it underline it as error.
    I suppose that inside must be the number of the selected item from comboBox i mean 0 for first, 1 for next etc.

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

    Default Re: comboBox signal question?

    Maybe you misunderstand, what I mean is this:
    Qt Code:
    1. connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(combochanged(int)));
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: comboBox signal question?

    it works, thanks a lot!!!!

Similar Threads

  1. Color ComboBox
    By ioannis in forum Qt Programming
    Replies: 14
    Last Post: 23rd March 2016, 07:08
  2. Qtablewidget Combobox
    By aekilic in forum Qt Programming
    Replies: 17
    Last Post: 7th July 2015, 11:22
  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. Combobox Signals
    By b1 in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2006, 10:21

Tags for this Thread

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.