PDA

View Full Version : using *.ui file with QWizard



readyblue
15th January 2016, 14:53
Hi all,

I have used QDesigner to create the *.ui file,
can you please help with some example how to use that *.ui file and show the QWizard in it?

I was unable to find any example of such using only creating whole QWizard by code, not by *.ui

Many Thanks.

d_stranz
15th January 2016, 15:57
For each page, derive a class from QWizardPage. In that class, add the UI class either by multiple inheritance, a member variable, or a member variable pointer. In the QWizardPage class constructor, call setupUi( this ) as appropriate for the way you have added the UI class.

See the Qt examples for writing a custom QDialog or QWidget using Qt Designer. The procedure is exactly the same, only you use QWizardPage as the base class instead of QDialog or QWidget.

You then call QWizard::addPage() to put your customer page into the wizard.

readyblue
15th January 2016, 16:08
hi d_stranz,

I already have all the pages in the *.ui file

do not need to call QWizard::addPage() to do what already is in the *.ui file

how can I use the pages for QWizard from the *.ui file?

Thanks

d_stranz
15th January 2016, 16:16
Maybe this previous post (http://www.qtcentre.org/threads/21017-Can-you-create-a-custom-multi-page-QWizard-with-QtDesigner) will help you. I do not know which version of Qt it uses; if it is Qt 4, then some of the include files and modules in the .pro file might have changed.

anda_skoa
15th January 2016, 16:31
If you created a wizard in designer, i.e. you have a single .ui file and that contains all pages of the wizard, then you do the same thing you would do for any normal dialog or widget.

E.g. create a QWizard derived class, add the generated class as a member and call "setupUi(this)" in the constructor.

Cheers,
_

readyblue
15th January 2016, 18:48
@anda_skoa

I have tried your recommendation, yet there is error:

.../widget.cpp:9: error: no matching function for call to 'Ui::Widget::setupUi(Widget* const)'
ui->setupUi(this);
^

I have done just that: create new Widget project and add and change the *.ui file with QWizard
I am sorry, I have no idea what I am missing,
Can you please give me some hint? Thanks

ChrisW67
15th January 2016, 21:10
This is from memory so forgive me if it is not perfect

Pro file


...
HEADERS += wizard.h
SOURCES += wizard.cpp
FORMS += wizard.ui
...

Wizard.h


...
namespace Ui {
class Wizard;
};

class Wizard: public QWizard
{
Q_OBJECT
public:
Wizard(QWidget *p = 0);
~Wizard();
...
private:
Ui::Wizard *ui;
}

Wizard.cpp


#include "wizard.cpp"
#include "ui_wizard.h"

Wizard(QWidget *p):
QWizard(p),
ui(new Ui::Wizard)
{
ui->setupUi(this);
}

~Wizard()
{
delete ui;
}

readyblue
16th January 2016, 00:51
Thank you very much @ChrisW67 !!!

Just to save some little debugging to the future,
here is tested code fore someone else just to copy & paste.

wizadr.h

#include <QWizard>

namespace Ui {
class Widget;
}

class Wizard : public QWizard
{
Q_OBJECT

public:
explicit Wizard(QWidget *parent = 0);
~Wizard();

private:
Ui::Widget *ui;
};


wizard.cpp

#include "wizard.h"
#include "ui_wizard.h"

Wizard::Wizard(QWidget *parent) :
QWizard(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}

Wizard::~Wizard()
{
delete ui;
}

Thanks again everyone for help.