Search code examples
c++netbeansqt4signals-slots

QT4 no such slot error


I know there are many many questions that are just the same, but none of them helps me:

class Form1 : public QMainWindow {
    Q_OBJECT
public:
    Form1();
    virtual ~Form1();
public slots:
    void langChange(const char* lang_label);
private:
    Ui::Form1 widget;
    void setLangStrings();
};

From1 constructor:

Form1::Form1() {
    widget.setupUi(this);
    connect(widget.btnL0, SIGNAL(clicked(bool)), this, SLOT(langChange("en")));
    connect(widget.btnL1, SIGNAL(clicked(bool)), this, SLOT(langChange("fr")));
    setLangStrings();
}

And I also have this langChange function implemented:

void Form1::langChange(const char* lang_label)
{
    GL_LANG = lang_label;
    setLangStrings();
}

I get this stupid error when the connect function is called:

No such slot Form1::langChange("sl") in Form1.cpp:15

I'm using NetBeans with QDesigner for the UI. I must say this QT4 is very difficult to learn.


Solution

  • You simply can't connect SIGNAL with bool as argument to SLOT with const char* as argument. To do this kind of stuff you have to use QSignalMapper. You have an example how to use it inside documentation. In your case, it's very simple, so you should handle it easly.