Object::connect: No such slot QGroupBox::lcs_slot(bool)



  • Well, I’ve searched this many times in Google, and still I can’t solve it, so I ask for some help. I desigener it for using qt designer

    I’ve seen the documentation, and I think this is the way to declare a custom slot:
    My .h file
    @//=================extensiondlg.h=====================
    #ifndef EXTENSIONDLG_H
    #define EXTENSIONDLG_H
    #include <QDialog>
    #include "ui_extensionDlg.h"
    class ExtensionDlg:public QDialog,public Ui::Dialog
    {
    Q_OBJECT
    public:
    ExtensionDlg(QWidget *parent = 0);
    public slots:
    void lcs_slot(bool);
    };
    #endif@

    my .cpp file

    @//=====================extension.cpp=====================
    #include <QtGui>
    #include "extensionDlg.h"
    ExtensionDlg::ExtensionDlg(QWidget *parent)
    :QDialog(parent)
    {
    setupUi(this);
    this->extensionGroupBox->hide();
    verticalLayout_2->setSizeConstraint(QLayout::SetFixedSize);
    }

    void ExtensionDlg::lcs_slot(bool lcs)
    {
    if (lcs)
    {
    this->extensionGroupBox->hide();
    }
    else
    {
    this->extensionGroupBox->hide();
    }
    }

    @

    @//=======================main.cpp===================
    #include "extensionDlg.h"
    #include <QApplication>
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    ExtensionDlg *dlg = new ExtensionDlg;
    dlg->show();
    return app.exec();
    }
    //======================================================@
    ui_extensionDlg.h as follow..

    Thank you for any answers or help.



  • @//==================ui_extensionDlg.h======================
    /********************************************************************************
    ** Form generated from reading UI file 'extensionDlgDesigner.ui'
    **
    ** Created: Sun Apr 8 23:49:42 2012
    ** by: Qt User Interface Compiler version 4.7.0
    **
    ** WARNING! All changes made in this file will be lost when recompiling UI file!
    ********************************************************************************/

    #ifndef UI_EXTENSIONDLGDESIGNER_H
    #define UI_EXTENSIONDLGDESIGNER_H

    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QComboBox>
    #include <QtGui/QDialog>
    #include <QtGui/QFormLayout>
    #include <QtGui/QGroupBox>
    #include <QtGui/QHBoxLayout>
    #include <QtGui/QHeaderView>
    #include <QtGui/QLabel>
    #include <QtGui/QLineEdit>
    #include <QtGui/QPushButton>
    #include <QtGui/QSpacerItem>
    #include <QtGui/QVBoxLayout>

    QT_BEGIN_NAMESPACE

    class Ui_Dialog
    {
    public:
    QVBoxLayout *verticalLayout_2;
    QGroupBox *basicGroupBox;
    QVBoxLayout *verticalLayout;
    QFormLayout *formLayout;
    QLabel *nameLabel;
    QLineEdit *nameLineEdit;
    QLabel *sexLabel;
    QComboBox *sexComboBox;
    QHBoxLayout *horizontalLayout;
    QPushButton *okButton;
    QPushButton *detailButton;
    QSpacerItem *verticalSpacer;
    QGroupBox *extensionGroupBox;
    QFormLayout *formLayout_3;
    QFormLayout *formLayout_2;
    QLabel *label;
    QLineEdit *nameLineEdit_2;
    QLabel *label_2;
    QComboBox *sexComboBox_2;
    QLabel *label_3;
    QLineEdit *nameLineEdit_3;

    void setupUi(QDialog *Dialog)
    {
        if (Dialog->objectName().isEmpty())
            Dialog->setObjectName(QString::fromUtf8("Dialog"));
        Dialog->resize(284, 302);
        verticalLayout_2 = new QVBoxLayout(Dialog);
        verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
        basicGroupBox = new QGroupBox(Dialog);
        basicGroupBox->setObjectName(QString::fromUtf8("basicGroupBox"));
        verticalLayout = new QVBoxLayout(basicGroupBox);
        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
        formLayout = new QFormLayout();
        formLayout->setObjectName(QString::fromUtf8("formLayout"));
        nameLabel = new QLabel(basicGroupBox);
        nameLabel->setObjectName(QString::fromUtf8("nameLabel"));
    
        formLayout->setWidget(0, QFormLayout::LabelRole, nameLabel);
    
        nameLineEdit = new QLineEdit(basicGroupBox);
        nameLineEdit->setObjectName(QString::fromUtf8("nameLineEdit"));
    
        formLayout->setWidget(0, QFormLayout::FieldRole, nameLineEdit);
    
        sexLabel = new QLabel(basicGroupBox);
        sexLabel->setObjectName(QString::fromUtf8("sexLabel"));
    
        formLayout->setWidget(1, QFormLayout::LabelRole, sexLabel);
    
        sexComboBox = new QComboBox(basicGroupBox);
        sexComboBox->setObjectName(QString::fromUtf8("sexComboBox"));
    
        formLayout->setWidget(1, QFormLayout::FieldRole, sexComboBox);
    
    
        verticalLayout->addLayout(formLayout);
    
        horizontalLayout = new QHBoxLayout();
        horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
        okButton = new QPushButton(basicGroupBox);
        okButton->setObjectName(QString::fromUtf8("okButton"));
        okButton->setDefault(true);
    
        horizontalLayout->addWidget(okButton);
    
        detailButton = new QPushButton(basicGroupBox);
        detailButton->setObjectName(QString::fromUtf8("detailButton"));
        detailButton->setDefault(true);
    
        horizontalLayout->addWidget(detailButton);
    
    
        verticalLayout->addLayout(horizontalLayout);
    
    
        verticalLayout_2->addWidget(basicGroupBox);
    
        verticalSpacer = new QSpacerItem(20, 17, QSizePolicy::Minimum, QSizePolicy::Expanding);
    
        verticalLayout_2->addItem(verticalSpacer);
    
        extensionGroupBox = new QGroupBox(Dialog);
        extensionGroupBox->setObjectName(QString::fromUtf8("extensionGroupBox"));
        formLayout_3 = new QFormLayout(extensionGroupBox);
        formLayout_3->setObjectName(QString::fromUtf8("formLayout_3"));
        formLayout_2 = new QFormLayout();
        formLayout_2->setObjectName(QString::fromUtf8("formLayout_2"));
        label = new QLabel(extensionGroupBox);
        label->setObjectName(QString::fromUtf8("label"));
    
        formLayout_2->setWidget(0, QFormLayout::LabelRole, label);
    
        nameLineEdit_2 = new QLineEdit(extensionGroupBox);
        nameLineEdit_2->setObjectName(QString::fromUtf8("nameLineEdit_2"));
    
        formLayout_2->setWidget(0, QFormLayout::FieldRole, nameLineEdit_2);
    
        label_2 = new QLabel(extensionGroupBox);
        label_2->setObjectName(QString::fromUtf8("label_2"));
    
        formLayout_2->setWidget(1, QFormLayout::LabelRole, label_2);
    
        sexComboBox_2 = new QComboBox(extensionGroupBox);
        sexComboBox_2->setObjectName(QString::fromUtf8("sexComboBox_2"));
    
        formLayout_2->setWidget(1, QFormLayout::FieldRole, sexComboBox_2);
    
        label_3 = new QLabel(extensionGroupBox);
        label_3->setObjectName(QString::fromUtf8("label_3"));
    
        formLayout_2->setWidget(2, QFormLayout::LabelRole, label_3);
    
        nameLineEdit_3 = new QLineEdit(extensionGroupBox);
        nameLineEdit_3->setObjectName(QString::fromUtf8("nameLineEdit_3"));
    
        formLayout_2->setWidget(2, QFormLayout::FieldRole, nameLineEdit_3);
    
    
        formLayout_3->setLayout(0, QFormLayout::LabelRole, formLayout_2);
    
    
        verticalLayout_2->addWidget(extensionGroupBox);
    
    
        retranslateUi(Dialog);
        QObject::connect(okButton, SIGNAL(clicked()), Dialog, SLOT(accept()));
        QObject::connect(detailButton, SIGNAL(toggled(bool)), extensionGroupBox, SLOT(lcs_slot(bool)));
    
        QMetaObject::connectSlotsByName(Dialog);
    } // setupUi
    

    @
    //follow is on



  • @ void retranslateUi(QDialog *Dialog)
    {
    Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
    basicGroupBox->setTitle(QApplication::translate("Dialog", "Basic", 0, QApplication::UnicodeUTF8));
    nameLabel->setText(QApplication::translate("Dialog", "Name", 0, QApplication::UnicodeUTF8));
    sexLabel->setText(QApplication::translate("Dialog", "Sex", 0, QApplication::UnicodeUTF8));
    sexComboBox->clear();
    sexComboBox->insertItems(0, QStringList()
    << QApplication::translate("Dialog", "Male", 0, QApplication::UnicodeUTF8)
    << QApplication::translate("Dialog", "Female", 0, QApplication::UnicodeUTF8)
    );
    okButton->setText(QApplication::translate("Dialog", "OK", 0, QApplication::UnicodeUTF8));
    detailButton->setText(QApplication::translate("Dialog", "Detail", 0, QApplication::UnicodeUTF8));
    extensionGroupBox->setTitle(QApplication::translate("Dialog", "Extension", 0, QApplication::UnicodeUTF8));
    label->setText(QApplication::translate("Dialog", "Age", 0, QApplication::UnicodeUTF8));
    label_2->setText(QApplication::translate("Dialog", "Department", 0, QApplication::UnicodeUTF8));
    sexComboBox_2->clear();
    sexComboBox_2->insertItems(0, QStringList()
    << QApplication::translate("Dialog", "department1", 0, QApplication::UnicodeUTF8)
    << QApplication::translate("Dialog", "department2", 0, QApplication::UnicodeUTF8)
    << QApplication::translate("Dialog", "department3", 0, QApplication::UnicodeUTF8)
    );
    label_3->setText(QApplication::translate("Dialog", "Address", 0, QApplication::UnicodeUTF8));
    } // retranslateUi

    };

    namespace Ui {
    class Dialog: public Ui_Dialog {};
    } // namespace Ui

    QT_END_NAMESPACE

    #endif // UI_EXTENSIONDLGDESIGNER_H

    @



  • On line 117, you can see that:
    @ extensionGroupBox = new QGroupBox(Dialog);
    @

    Then, on line 162, you make the connection:
    @
    QObject::connect(detailButton, SIGNAL(toggled(bool)), extensionGroupBox, SLOT(lcs_slot(bool)));
    @

    So, you are trying to connect to the lcs_slot in a QGroupBox, but the slot really exists in a your ExtensionDlg class. That's where you go wrong.

    Did you by any chance manually modify the ui_extensionDlg.h file? If so: don't.



  • Thank you for answer my question, as you say ,Indeed i alter the ui_extensionDlg.h file, that is 162 line,
    The original is QObject::connect(detailButton, SIGNAL(toggled(bool)), extensionGroupBox, SLOT(setVisibile));
    but It's not work, so i alter it. How to solve this problem?



  • Never alter the generated ui_*.h files. From the top of my head, there is even a warning at the top of this file to tell you so. The file will be overwritten the next time you build the application...

    You can solve this by making the connection in the extensionDlg.cpp file, right after your setupUi() call.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.