tags:

views:

182

answers:

2

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:

  • there clearly is such a function. You can look it up in the class definition of QStackedWidget. What is going on here?
  • Why is the first character of the compiler output a '0', while my source code clearly and correctly shows it as 'Q'?

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!

+5  A: 

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.

rpg
Oops, beat me to it, and you talked about parameter mismatch. +1
Bill
Yeah, I've also had some trouble with those pesky little things lately :)
rpg
Yes, you can consume fewer parameters than are emitted.
Bill
+3  A: 

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.

Bill