-1

I have this listWidget that displays a list of dogs (name - breed) . I have this comboBox that is supposed to let me choose between displaying short version (just name - breed) or detailed version (name - breed - age - weight - photograph). For some reason, my comboBox doesn't do anything, even if my connection doesn't give me any errors. This is how I implemented it:

QObject::connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_comboBox_event(int)));

void QtGuiApplication::on_comboBox_event(int selection)
{
    switch (selection) {
    case 0:
        this->populateDogsList();
        break;
    case 1:
        this->populateDogsListDetailed();
        break;

    }

}

What am I doing wrong? Please do help me, I've looked everywhere :/ Thanks. PS. My populate list method works by itself, I can't even debug it since it doesn't enter the comboBox event method.

Class definition : (header) class QtGuiApplication : public QMainWindow { Q_OBJECT

public: QtGuiApplication(Controller& ctrl, QWidget *parent = Q_NULLPTR); ~QtGuiApplication() {};

(code)

Bryuki HK
  • 41
  • 4
  • The posted code looks correct; so the error is likely elsewhere in your program; you'll need to perform some tests to narrow down where the problem is located. e.g. Are any warnings printed to stdout when the program runs? Is 'this' pointing to your QtGuiApplication object? If you put a printf() (or qDebug() or etc) call next to our QObject::connect() line, does it print out when your program runs? If you put one at the top of your on_comboBox_event() method, does it print out when you select an item from the combo box? – Jeremy Friesner May 24 '18 at 14:23
  • It seems it says something : No such slot QtGuiApplication::on_comboBox_event(int) in d:\microsoft visual studio\lab5-6\qtguiapplication\qtguiapplication\qtguiapplication.cpp:21 :D – Bryuki HK May 24 '18 at 14:36
  • Can you post your class definition? – Isma May 24 '18 at 14:42
  • class QtGuiApplication : public QMainWindow { Q_OBJECT public: QtGuiApplication(Controller& ctrl, QWidget *parent = Q_NULLPTR); ~QtGuiApplication() {}; – Bryuki HK May 24 '18 at 14:48
  • https://stackoverflow.com/q/26422154/1421332 – Silicomancer May 26 '18 at 10:19

1 Answers1

0

Your comment "No such slot QtGuiApplication::on_comboBox_event(int)" suggests that the header file for QtGuiApplication does not declare this member function as a slot, it should look like this:

class QtGuiApplication: public ...
{
    Q_OBJECT
...
public slots:
    void on_comboBox_event(int);
...
}

Qt uses a tool called moc.exe to parse header files, which generates code for slot lookup. In your case the slot is probably not found because of the missing declaration.

Ron Kluth
  • 51
  • 3