Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QWizardPage question



  • Hi all and thank you for your time.
    For my little db app I want to have a wizard with a page, on which there are two radio buttons and a combo box. The first radio button should be selected by default. The combo box should be disabled -> no problem so far.
    .However: the combo box should be enabled, when the second of the two radio buttons is pressed.
    How can I achieve this?
    Best regards
    Holger



  • @jsulm - you are right, sorry. This is current - but it does not link with an error "undefined reference to vtable" ...

    class wizNewOrExistingPage : public QWizardPage
    {
        Q_OBJECT
    public:
        wizNewOrExistingPage(QWidget* );
        void initializePage() override;
    public slots:
        void onExistingCreditor_toggled(bool );
    ...
    
    wizNewOrExistingPage::wizNewOrExistingPage(QWidget* p) : QWizardPage(p)
    {
        rbNew =new QRadioButton(qsl("do this"));
        rbExisting =new QRadioButton(qsl("do other"));
        registerField(qsl("create_new"), rbNew);
        cbCreditors = new QComboBox();
        QVBoxLayout* l =new QVBoxLayout();
        l->addWidget(rbNew);
        l->addWidget(rbExisting);
        l->addWidget(cbCreditors);
        setLayout(l);
        connect(rbExisting, SIGNAL(toggled(bool)), this, SLOT(onExistingCreditor_toggled(bool)));
    }
    
    void wizNewOrExistingPage::onExistingCreditor_toggled(bool b)
    {
        cbCreditors->setEnabled(b);
    }
    

  • Qt Champions 2019

    @HoMa said in QWizardPage question:

    How can I achieve this?

    Quite easy actually: connect https://doc.qt.io/qt-5/qabstractbutton.html#toggled from the second radio button to a slot where you then call https://doc.qt.io/qt-5/qwidget.html#enabled-prop on the combo box.



  • Wow - that was a quick one! Thanks a lot - I will try this.

    btw: I never read the docu to QAbstractButton before ...


  • Qt Champions 2019

    @HoMa said in QWizardPage question:

    QAbstractButton

    It's the base class of QRadioButton
    See "Inherits: QAbstractButton" in https://doc.qt.io/qt-5/qradiobutton.html
    To see everything including inherited methods/properties click on "List of all members, including inherited members".



  • @jsulm
    :( obviously I am not "fluent" enough with signals and slots. Can you check why this does not work (this is in the contructor of the QWizardPage):

    setTitle(qsl("title"));
        rbNew =new QRadioButton(qsl("do this"));
        rbExisting =new QRadioButton(qsl("select that"));
        registerField(qsl("create_new"), rbNew);
        cbCreditors = new QComboBox();
        QVBoxLayout* l =new QVBoxLayout();
        l->addWidget(rbNew);
        l->addWidget(rbExisting);
        l->addWidget(cbCreditors);
        setLayout(l);
        connect(rbExisting, &rbExisting->toggled, this, &this->onExistingCreditor_toggled);
    

  • Moderators

    @HoMa said in QWizardPage question:

    connect(rbExisting, &rbExisting->toggled, this, &this->onExistingCreditor_toggled);

    this is not the correct syntax for a function pointer!

    connect(rbExisting, & QRadioButton::toggled, this, &MyClass::onExistingCreditor_toggled);



  • I slowly advance ;)

    This

    connect(rbExisting, SIGNAL(toggled()), this, 
    SLOT(onExistingCreditor_toggled()));
    

    compiles, but gives me an error at runtime:

    QObject::connect: No such signal QRadioButton::toggled()
    

    But that was what we got from the QAbstractButton, right?
    One last hint ...?


  • Qt Champions 2019

    @HoMa Please read documentation https://doc.qt.io/qt-5/qabstractbutton.html#toggled
    Hint: the signal has a parameter...



  • @jsulm you are right again - but

    connect(rbExisting, SIGNAL(toggled(bool)), this, SLOT(onExistingCreditor_toggled(bool)));
    

    gives me

    QObject::connect: No such slot QWizardPage::onExistingCreditor_toggled(bool)
    

    :/ am I the only one who finds this confusing?


  • Qt Champions 2019

    @HoMa Because your slot does not have parameters, simply remove "bool"...
    A slot is allowed to have less parameters than signal (but not the other way around).



  • @jsulm 1000x thanks that you are so patient.
    However: this does not do the trick. I tried both ways: with and w/o parameter in the function definition as well as in the connect call.
    The error mentioned QWizardPage... shouldn't it be about my class (which is derived from QWizardPage)?
    regards
    Holger


  • Qt Champions 2019

    @HoMa Can you show your current connect call and slot declaration? Without code I can't tell you much.



  • @jsulm - you are right, sorry. This is current - but it does not link with an error "undefined reference to vtable" ...

    class wizNewOrExistingPage : public QWizardPage
    {
        Q_OBJECT
    public:
        wizNewOrExistingPage(QWidget* );
        void initializePage() override;
    public slots:
        void onExistingCreditor_toggled(bool );
    ...
    
    wizNewOrExistingPage::wizNewOrExistingPage(QWidget* p) : QWizardPage(p)
    {
        rbNew =new QRadioButton(qsl("do this"));
        rbExisting =new QRadioButton(qsl("do other"));
        registerField(qsl("create_new"), rbNew);
        cbCreditors = new QComboBox();
        QVBoxLayout* l =new QVBoxLayout();
        l->addWidget(rbNew);
        l->addWidget(rbExisting);
        l->addWidget(cbCreditors);
        setLayout(l);
        connect(rbExisting, SIGNAL(toggled(bool)), this, SLOT(onExistingCreditor_toggled(bool)));
    }
    
    void wizNewOrExistingPage::onExistingCreditor_toggled(bool b)
    {
        cbCreditors->setEnabled(b);
    }
    

  • Qt Champions 2019

    @HoMa said in QWizardPage question:

    "undefined reference to vtable"

    Do a complete rebuild: remove build folder, run qmake and build.



  • @jsulm exactly ! I just found out no my own. That is strange.

    Anyhow: great! Learned a lot on signals and slots - Thanks a lot!


Log in to reply