Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I overwrite the "next" slot in a QWizard?

Tags:

c++

qt

qt4

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

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

Is this because this next slot is virtual protected? How can I do some things after the next button is clicked?


The header file of my QWizard class follows. 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

I create a new wizard instance via 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 built in ui_PrimerWizard.h by this function:

QMetaObject::connectSlotsByName(PrimerWizard);
like image 212
Claire Huang Avatar asked Nov 06 '22 10:11

Claire Huang


1 Answers

The next slot cannot be overwritten. However, the validatePage function for QWizardPage can. This function will be called when the "Next" or "Finish" button is clicked.

like image 131
Claire Huang Avatar answered Nov 11 '22 02:11

Claire Huang