tags:

views:

56

answers:

3

Hi: I'm using a QWizard class, which contains several QWizardPage. For some pages, I need to do something when "Next" button is clicked.

I tried to overwrite the "next" slot in QWizard class, however, it seems this doesn't work. the program still went into the original "next" slot in QWizard class instead the one I implemented.

Does this because of that this next slot is virtual protected? How can I do some things after the next button is clicked?? Thanks for your help.

Follows is the header file of my QWizard class: By the way, the "accept" signal works fine as what I expected.

#ifndef PRIMERWIZARD_H
#define PRIMERWIZARD_H

#include <QWizard>

namespace Ui {
    class PrimerWizard;
}

class PrimerWizard : public QWizard {
    Q_OBJECT
public:
    PrimerWizard(QWidget *parent = 0);
    ~PrimerWizard();
protected slots:
    void next();
    void accept();

protected:
    void changeEvent(QEvent *e);

private:
    Ui::PrimerWizard *ui;
};

#endif // PRIMERWIZARD_H

Can you show the code where you create new wizard instance and connect some signals with its slots?

P.S. I can't leave comments so I've written this as answer. Sorry =)

I create new wizard instance by the QtCreator's wizard (Ha XD) The code is as follows:

PrimerWizard* pW = new PrimerWizard(this);
pW->exec();

And the signal-slot connection of "next" is created by QtCreator, I cannot find where it's actually connected. I think the connection is builded in ui_PrimerWizard.h by the function:

QMetaObject::connectSlotsByName(PrimerWizard);
A: 

You are missing the virtual keyword in your function definitions. It won't work unless it is defined exactly like the base class.

Gianni
It still doesn't works ><.....
Claire Huang
virtual is optional in reimplementations
A: 

Can you show the code where you create new wizard instance and connect some signals with its slots?

P.S. I can't leave comments so I've written this as answer. Sorry =)

GooRoo
Now I've shown these in the bottom of my question, hope that can give you more information, Thanks :)
Claire Huang
I've just tryed to override next() slot too but it seems this is not right way.Maybe you would try to find another way for implementing what you want. For example, if you need to do some things after active page is changed (actually, next-button do this as well) you can use signal currentIdChanged(int).
GooRoo
Thanks, I'll try to find some other ways. :)I just wonder if there is a better way to take advantage of the existed slots.
Claire Huang
A: 

the "next" slot cannot be overwrite, however, the "validatePage" function for QWizardPage can, this function will be called when "Next" or "Finish" button is clicked.

Claire Huang