April 9, 2012

lcsqt lcsqt
Lab Rat
4 posts

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

  1. //=================extensiondlg.h=====================
  2. #ifndef EXTENSIONDLG_H
  3. #define EXTENSIONDLG_H
  4. #include <QDialog>
  5. #include "ui_extensionDlg.h"
  6. class ExtensionDlg:public QDialog,public Ui::Dialog
  7. {
  8.     Q_OBJECT
  9.     public:
  10.         ExtensionDlg(QWidget *parent = 0);
  11.     public slots:
  12.         void lcs_slot(bool);
  13. };
  14. #endif

my .cpp file

  1. //=====================extension.cpp=====================
  2. #include <QtGui>
  3. #include "extensionDlg.h"
  4. ExtensionDlg::ExtensionDlg(QWidget *parent)
  5.         :QDialog(parent)
  6. {
  7.     setupUi(this);
  8.     this->extensionGroupBox->hide();
  9.     verticalLayout_2->setSizeConstraint(QLayout::SetFixedSize);
  10. }
  11.  
  12. void ExtensionDlg::lcs_slot(bool lcs)
  13. {
  14.     if (lcs)
  15.     {
  16.         this->extensionGroupBox->hide();
  17.     }
  18.     else
  19.     {
  20.         this->extensionGroupBox->hide();
  21.     }
  22. }

  1. //=======================main.cpp===================
  2. #include "extensionDlg.h"
  3. #include <QApplication>
  4. int main(int argc, char *argv[])
  5. {
  6.        QApplication app(argc, argv);
  7.        ExtensionDlg *dlg = new ExtensionDlg;
  8.        dlg->show();
  9.        return app.exec();
  10. }
  11. //======================================================

ui_extensionDlg.h as follow..

Thank you for any answers or help.

5 replies

April 9, 2012

lcsqt lcsqt
Lab Rat
4 posts

  1. //==================ui_extensionDlg.h======================
  2. /********************************************************************************
  3. ** Form generated from reading UI file 'extensionDlgDesigner.ui'
  4. **
  5. ** Created: Sun Apr 8 23:49:42 2012
  6. **      by: Qt User Interface Compiler version 4.7.0
  7. **
  8. ** WARNING! All changes made in this file will be lost when recompiling UI file!
  9. ********************************************************************************/
  10.  
  11. #ifndef UI_EXTENSIONDLGDESIGNER_H
  12. #define UI_EXTENSIONDLGDESIGNER_H
  13.  
  14. #include <QtCore/QVariant>
  15. #include <QtGui/QAction>
  16. #include <QtGui/QApplication>
  17. #include <QtGui/QButtonGroup>
  18. #include <QtGui/QComboBox>
  19. #include <QtGui/QDialog>
  20. #include <QtGui/QFormLayout>
  21. #include <QtGui/QGroupBox>
  22. #include <QtGui/QHBoxLayout>
  23. #include <QtGui/QHeaderView>
  24. #include <QtGui/QLabel>
  25. #include <QtGui/QLineEdit>
  26. #include <QtGui/QPushButton>
  27. #include <QtGui/QSpacerItem>
  28. #include <QtGui/QVBoxLayout>
  29.  
  30. QT_BEGIN_NAMESPACE
  31.  
  32. class Ui_Dialog
  33. {
  34. public:
  35.     QVBoxLayout *verticalLayout_2;
  36.     QGroupBox *basicGroupBox;
  37.     QVBoxLayout *verticalLayout;
  38.     QFormLayout *formLayout;
  39.     QLabel *nameLabel;
  40.     QLineEdit *nameLineEdit;
  41.     QLabel *sexLabel;
  42.     QComboBox *sexComboBox;
  43.     QHBoxLayout *horizontalLayout;
  44.     QPushButton *okButton;
  45.     QPushButton *detailButton;
  46.     QSpacerItem *verticalSpacer;
  47.     QGroupBox *extensionGroupBox;
  48.     QFormLayout *formLayout_3;
  49.     QFormLayout *formLayout_2;
  50.     QLabel *label;
  51.     QLineEdit *nameLineEdit_2;
  52.     QLabel *label_2;
  53.     QComboBox *sexComboBox_2;
  54.     QLabel *label_3;
  55.     QLineEdit *nameLineEdit_3;
  56.  
  57.     void setupUi(QDialog *Dialog)
  58.     {
  59.         if (Dialog->objectName().isEmpty())
  60.             Dialog->setObjectName(QString::fromUtf8("Dialog"));
  61.         Dialog->resize(284, 302);
  62.         verticalLayout_2 = new QVBoxLayout(Dialog);
  63.         verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
  64.         basicGroupBox = new QGroupBox(Dialog);
  65.         basicGroupBox->setObjectName(QString::fromUtf8("basicGroupBox"));
  66.         verticalLayout = new QVBoxLayout(basicGroupBox);
  67.         verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
  68.         formLayout = new QFormLayout();
  69.         formLayout->setObjectName(QString::fromUtf8("formLayout"));
  70.         nameLabel = new QLabel(basicGroupBox);
  71.         nameLabel->setObjectName(QString::fromUtf8("nameLabel"));
  72.  
  73.         formLayout->setWidget(0, QFormLayout::LabelRole, nameLabel);
  74.  
  75.         nameLineEdit = new QLineEdit(basicGroupBox);
  76.         nameLineEdit->setObjectName(QString::fromUtf8("nameLineEdit"));
  77.  
  78.         formLayout->setWidget(0, QFormLayout::FieldRole, nameLineEdit);
  79.  
  80.         sexLabel = new QLabel(basicGroupBox);
  81.         sexLabel->setObjectName(QString::fromUtf8("sexLabel"));
  82.  
  83.         formLayout->setWidget(1, QFormLayout::LabelRole, sexLabel);
  84.  
  85.         sexComboBox = new QComboBox(basicGroupBox);
  86.         sexComboBox->setObjectName(QString::fromUtf8("sexComboBox"));
  87.  
  88.         formLayout->setWidget(1, QFormLayout::FieldRole, sexComboBox);
  89.  
  90.  
  91.         verticalLayout->addLayout(formLayout);
  92.  
  93.         horizontalLayout = new QHBoxLayout();
  94.         horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
  95.         okButton = new QPushButton(basicGroupBox);
  96.         okButton->setObjectName(QString::fromUtf8("okButton"));
  97.         okButton->setDefault(true);
  98.  
  99.         horizontalLayout->addWidget(okButton);
  100.  
  101.         detailButton = new QPushButton(basicGroupBox);
  102.         detailButton->setObjectName(QString::fromUtf8("detailButton"));
  103.         detailButton->setDefault(true);
  104.  
  105.         horizontalLayout->addWidget(detailButton);
  106.  
  107.  
  108.         verticalLayout->addLayout(horizontalLayout);
  109.  
  110.  
  111.         verticalLayout_2->addWidget(basicGroupBox);
  112.  
  113.         verticalSpacer = new QSpacerItem(20, 17, QSizePolicy::Minimum, QSizePolicy::Expanding);
  114.  
  115.         verticalLayout_2->addItem(verticalSpacer);
  116.  
  117.         extensionGroupBox = new QGroupBox(Dialog);
  118.         extensionGroupBox->setObjectName(QString::fromUtf8("extensionGroupBox"));
  119.         formLayout_3 = new QFormLayout(extensionGroupBox);
  120.         formLayout_3->setObjectName(QString::fromUtf8("formLayout_3"));
  121.         formLayout_2 = new QFormLayout();
  122.         formLayout_2->setObjectName(QString::fromUtf8("formLayout_2"));
  123.         label = new QLabel(extensionGroupBox);
  124.         label->setObjectName(QString::fromUtf8("label"));
  125.  
  126.         formLayout_2->setWidget(0, QFormLayout::LabelRole, label);
  127.  
  128.         nameLineEdit_2 = new QLineEdit(extensionGroupBox);
  129.         nameLineEdit_2->setObjectName(QString::fromUtf8("nameLineEdit_2"));
  130.  
  131.         formLayout_2->setWidget(0, QFormLayout::FieldRole, nameLineEdit_2);
  132.  
  133.         label_2 = new QLabel(extensionGroupBox);
  134.         label_2->setObjectName(QString::fromUtf8("label_2"));
  135.  
  136.         formLayout_2->setWidget(1, QFormLayout::LabelRole, label_2);
  137.  
  138.         sexComboBox_2 = new QComboBox(extensionGroupBox);
  139.         sexComboBox_2->setObjectName(QString::fromUtf8("sexComboBox_2"));
  140.  
  141.         formLayout_2->setWidget(1, QFormLayout::FieldRole, sexComboBox_2);
  142.  
  143.         label_3 = new QLabel(extensionGroupBox);
  144.         label_3->setObjectName(QString::fromUtf8("label_3"));
  145.  
  146.         formLayout_2->setWidget(2, QFormLayout::LabelRole, label_3);
  147.  
  148.         nameLineEdit_3 = new QLineEdit(extensionGroupBox);
  149.         nameLineEdit_3->setObjectName(QString::fromUtf8("nameLineEdit_3"));
  150.  
  151.         formLayout_2->setWidget(2, QFormLayout::FieldRole, nameLineEdit_3);
  152.  
  153.  
  154.         formLayout_3->setLayout(0, QFormLayout::LabelRole, formLayout_2);
  155.  
  156.  
  157.         verticalLayout_2->addWidget(extensionGroupBox);
  158.  
  159.  
  160.         retranslateUi(Dialog);
  161.         QObject::connect(okButton, SIGNAL(clicked()), Dialog, SLOT(accept()));
  162.         QObject::connect(detailButton, SIGNAL(toggled(bool)), extensionGroupBox, SLOT(lcs_slot(bool)));
  163.  
  164.         QMetaObject::connectSlotsByName(Dialog);
  165.     } // setupUi
//follow is on

April 9, 2012

lcsqt lcsqt
Lab Rat
4 posts
  1.  void retranslateUi(QDialog *Dialog)
  2.     {
  3.         Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
  4.         basicGroupBox->setTitle(QApplication::translate("Dialog", "Basic", 0, QApplication::UnicodeUTF8));
  5.         nameLabel->setText(QApplication::translate("Dialog", "Name", 0, QApplication::UnicodeUTF8));
  6.         sexLabel->setText(QApplication::translate("Dialog", "Sex", 0, QApplication::UnicodeUTF8));
  7.         sexComboBox->clear();
  8.         sexComboBox->insertItems(0, QStringList()
  9.          << QApplication::translate("Dialog", "Male", 0, QApplication::UnicodeUTF8)
  10.          << QApplication::translate("Dialog", "Female", 0, QApplication::UnicodeUTF8)
  11.         );
  12.         okButton->setText(QApplication::translate("Dialog", "OK", 0, QApplication::UnicodeUTF8));
  13.         detailButton->setText(QApplication::translate("Dialog", "Detail", 0, QApplication::UnicodeUTF8));
  14.         extensionGroupBox->setTitle(QApplication::translate("Dialog", "Extension", 0, QApplication::UnicodeUTF8));
  15.         label->setText(QApplication::translate("Dialog", "Age", 0, QApplication::UnicodeUTF8));
  16.         label_2->setText(QApplication::translate("Dialog", "Department", 0, QApplication::UnicodeUTF8));
  17.         sexComboBox_2->clear();
  18.         sexComboBox_2->insertItems(0, QStringList()
  19.          << QApplication::translate("Dialog", "department1", 0, QApplication::UnicodeUTF8)
  20.          << QApplication::translate("Dialog", "department2", 0, QApplication::UnicodeUTF8)
  21.          << QApplication::translate("Dialog", "department3", 0, QApplication::UnicodeUTF8)
  22.         );
  23.         label_3->setText(QApplication::translate("Dialog", "Address", 0, QApplication::UnicodeUTF8));
  24.     } // retranslateUi
  25.  
  26. };
  27.  
  28. namespace Ui {
  29.     class Dialog: public Ui_Dialog {};
  30. } // namespace Ui
  31.  
  32. QT_END_NAMESPACE
  33.  
  34. #endif // UI_EXTENSIONDLGDESIGNER_H

April 9, 2012

Andre Andre
Area 51 Engineer
6031 posts

On line 117, you can see that:

  1.  extensionGroupBox = new QGroupBox(Dialog);

Then, on line 162, you make the connection:

  1. 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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 13, 2012

lcsqt lcsqt
Lab Rat
4 posts

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), extensionGroupBox, SLOT);
but It’s not work, so i alter it. How to solve this problem?

April 13, 2012

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

 
  ‹‹ *[SOLVED]* Multiple signals and single slot...      How display Time (hh:mm:ss) not statically? ››

You must log in to post a reply. Not a member yet? Register here!