bastibe
bastibe

Reputation: 17189

Qt doesn't find QStackedWidgets' slot setCurrentWidget

I am writing a wizard-style application in Qt that uses a QStackedWidget to organize the individual pages of the wizard. Now I want to switch between the pages, which should be possible using the function setCurrentWidget(...):

I have a simple main class that instantiates a QWidget audioconfig. Then, it adds this QWidget to a QStackedWidget pageStack using pageStack.addWidget(&audioconfig);.

Later, I want to connect a certain signal from a different QWidget hub to setCurrentWidget(...) of the QStackedWidget in order to switch the page. However, my compiler remarks that

0Object::connect: No such slot QStackedWidget::setCurrentWidget(audioconfig) in /Users/paperflyer/Development/App/main.cpp:41`

There are two things I don't get here:

Here is the whole code:

int main(int argc, char *argv[])
{
    QApplication app(argc,argv);
    QStackedWidget pageStack;
    CHub hub; // inherits from CWidget
    CAudioConfig audioconfig; // ditto
    pageStack.addWidget(&hub);
    pageStack.addWidget(&audioconfig);

    // connect() is a custom signal of hub
    QObject::connect(&hub, SIGNAL(configure()), &pageStack, SLOT(setCurrentWidget(&audioconfig)));

    pageStack.setGeometry(100,100,700,500);

    pageStack.show();
    return app.exec();
}

As always, thank you so much for your help!

Upvotes: 0

Views: 1522

Answers (2)

rpg
rpg

Reputation: 7777

QObject::connect(&hub, SIGNAL(configure()), &pageStack, SLOT(setCurrentWidget(&audioconfig)));

When you connect a signal to a signal/slot, you connect a signature. The actual parameters are passed when emitting the signal. The above should probably be setCurrentWidget(QWidget*), but even so it won't work, because the signature for the signal must match the one of the slot.

Note: I think that if the signal has more parameters than the slot it will still work, provided that the first parameters are the same.

Upvotes: 5

Bill
Bill

Reputation: 14675

Your connect line is wrong. It should be:

// connect() is a custom signal of hub
QObject::connect(
  &hub,     SIGNAL(configure()),
  &pageStack, SLOT(setCurrentWidget(QWidget *)));  // <- change here

You connect based on the prototype of the slot and/or signal.

Upvotes: 3

Related Questions