Connect QComboBox signal to working slot - signal setup required [Solved]

I'm trying to get the signal when my combobox is changed, but the following linw crashes DAZ Studio - 

    connect( m_MatList, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()) ); // trying to connect to the selection chamged signal on my combobox - crashes DAZ
this connect right above it works -

connect( dzScene, SIGNAL(primarySelectionChanged(DzNode*)), this, SLOT(refresh()) ); 

Defined as - 
class UVTailorPane : public DzPane {
    Q_OBJECT
    QComboBox        *m_MatList;

created as (in main constructor just aboe connect call)  -
    m_MatList = new QComboBox();
    mainLyt->addWidget( m_MatList );

combobox works and I clear and load it as things change, just can't get signals to work

Any ideas??

Thanks,
David

Post edited by Greenbriar Studio on

Comments

  • surrealsurreal Posts: 155

    In QComboBox the currentIndexChanged signal is overloaded

    i.e.

           void  currentIndexChanged(int index)
           void  currentIndexChanged(const QString & text)

    You could try just adding a second connect statement

         connect( m_MatList, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(refresh()) );

    or you could use the recommendation in the QT5 help on the subject.

    http://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged

    Note:Signal currentIndexChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:

    connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),    [=](int index){ /* ... */ });

     

  • surrealsurreal Posts: 155

    I don't think my comment above is relevant. I have just done some testing and currentIndexChanged(int index) worked fine even when inputting text into the QComboBox. It is currentIndexChanged(const QString&) that does not fire when manually inputting text into the QComboBox (rather than select from list).

    I suspect that your issue may be your MOC files again.

  • surrealsurreal Posts: 155

    Correction!  I don't think my comment above is NOT relevant.

  • How do you put that into a connect( m_MatList, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(refresh()) ); statement?

    Not matter how I have tried it, I get 'no overloaded connect matches' error.

    But it does look this is the problem.
    But all the online examples I can find just use the basic connect example, which doesn't work. (Older examples maybe before the extra versions came out in 5?)

    Signals for other widgets - checkboxes and pushbuttons - work fine, but they are not overloaded.
    Sadly, all but one of the combobox signals are overloaded., but knowing when it is used is critical. (the index is not, I can easily read the current value.)

  • That is because you have "const QString&" in the signal, the currentIndexChanged function will return an integer value (see documentation), change it to...

    connect(this->m_MatList, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()));

    Should work for you.

  • I finally got the basic version to work -

    connect( m_MatList, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()) ); 

    I still had an issue with the MOC string pointers, plus the combobox was triggering while it was being setup - normal gui issue. I had to set a flag while clearing and resetting it to suppress my response while I was working on it.
    Works fine now. My screw up.

    The static define is not required to call the overloaded operator signal in the SDK, just not screwing anything else up is required! :)

    Figuring out the MOC code this week has been a challenge.

Sign In or Register to comment.