Results 1 to 8 of 8

Thread: "No such slot..."

  1. #1
    Join Date
    May 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default "No such slot..."

    So, i'm very newbie. I've started with The Book of Qt4 but i stucked. Chapter 3, ByteConverter via QDesigner. After couple of days i managed this example to start the window and validate data in the fields but i still can't force it to convert them because...

    Object::connect: No such slot QDialog::decChanged(QString)
    Object::connect: (sender name: 'decEdit')
    Object::connect: (receiver name: 'Dialog')
    Object::connect: No such slot QDialog::hexChanged(QString)
    Object::connect: (sender name: 'hexEdit')
    Object::connect: (receiver name: 'Dialog')
    Object::connect: No such slot QDialog::binChanged(QString)
    Object::connect: (sender name: 'binEdit')
    Object::connect: (receiver name: 'Dialog')
    And here are my files:

    dialog.h:
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5. #include "ui_byteconverterdialog.h"
    6.  
    7. namespace Ui {
    8. class Dialog;
    9. }
    10.  
    11. class Dialog : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit Dialog(QWidget *parent = 0);
    17. ~Dialog();
    18.  
    19. private:
    20. Ui::Dialog *ui;
    21.  
    22.  
    23. private slots:
    24. // void decChanged (const QString&);
    25. // void hexChanged (const QString&);
    26. // void binChanged (const QString&);
    27. };
    28.  
    29. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    ui_byteconverterdialog.h:
    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'byteconverterdialog.ui'
    3. **
    4. ** Created: Thu May 10 20:34:47 2012
    5. ** by: Qt User Interface Compiler version 4.8.1
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_BYTECONVERTERDIALOG_H
    11. #define UI_BYTECONVERTERDIALOG_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QDialog>
    18. #include <QtGui/QDialogButtonBox>
    19. #include <QtGui/QGridLayout>
    20. #include <QtGui/QHBoxLayout>
    21. #include <QtGui/QHeaderView>
    22. #include <QtGui/QLabel>
    23. #include <QtGui/QLineEdit>
    24. #include <QtGui/QSpacerItem>
    25. #include <QtGui/QVBoxLayout>
    26. #include <QtGui/QWidget>
    27.  
    28. QT_BEGIN_NAMESPACE
    29.  
    30. class Ui_Dialog
    31. {
    32. public:
    33. QWidget *layoutWidget;
    34. QVBoxLayout *verticalLayout_2;
    35. QGridLayout *gridLayout;
    36. QLabel *label;
    37. QVBoxLayout *verticalLayout;
    38. QLineEdit *decEdit;
    39. QLineEdit *hexEdit;
    40. QLineEdit *binEdit;
    41. QLabel *label_2;
    42. QLabel *label_3;
    43. QSpacerItem *verticalSpacer;
    44. QHBoxLayout *horizontalLayout;
    45. QSpacerItem *horizontalSpacer;
    46. QDialogButtonBox *buttonBox;
    47.  
    48. void setupUi(QDialog *Dialog)
    49. {
    50. if (Dialog->objectName().isEmpty())
    51. Dialog->setObjectName(QString::fromUtf8("Dialog"));
    52. Dialog->resize(331, 261);
    53. layoutWidget = new QWidget(Dialog);
    54. layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
    55. layoutWidget->setGeometry(QRect(10, 10, 311, 241));
    56. verticalLayout_2 = new QVBoxLayout(layoutWidget);
    57. verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
    58. verticalLayout_2->setContentsMargins(0, 0, 0, 0);
    59. gridLayout = new QGridLayout();
    60. gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    61. label = new QLabel(layoutWidget);
    62. label->setObjectName(QString::fromUtf8("label"));
    63.  
    64. gridLayout->addWidget(label, 0, 0, 1, 1);
    65.  
    66. verticalLayout = new QVBoxLayout();
    67. verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
    68. decEdit = new QLineEdit(layoutWidget);
    69. decEdit->setObjectName(QString::fromUtf8("decEdit"));
    70.  
    71. verticalLayout->addWidget(decEdit);
    72.  
    73. hexEdit = new QLineEdit(layoutWidget);
    74. hexEdit->setObjectName(QString::fromUtf8("hexEdit"));
    75.  
    76. verticalLayout->addWidget(hexEdit);
    77.  
    78. binEdit = new QLineEdit(layoutWidget);
    79. binEdit->setObjectName(QString::fromUtf8("binEdit"));
    80.  
    81. verticalLayout->addWidget(binEdit);
    82.  
    83.  
    84. gridLayout->addLayout(verticalLayout, 0, 1, 3, 1);
    85.  
    86. label_2 = new QLabel(layoutWidget);
    87. label_2->setObjectName(QString::fromUtf8("label_2"));
    88.  
    89. gridLayout->addWidget(label_2, 1, 0, 1, 1);
    90.  
    91. label_3 = new QLabel(layoutWidget);
    92. label_3->setObjectName(QString::fromUtf8("label_3"));
    93.  
    94. gridLayout->addWidget(label_3, 2, 0, 1, 1);
    95.  
    96.  
    97. verticalLayout_2->addLayout(gridLayout);
    98.  
    99. verticalSpacer = new QSpacerItem(20, 98, QSizePolicy::Minimum, QSizePolicy::Expanding);
    100.  
    101. verticalLayout_2->addItem(verticalSpacer);
    102.  
    103. horizontalLayout = new QHBoxLayout();
    104. horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
    105. horizontalSpacer = new QSpacerItem(248, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    106.  
    107. horizontalLayout->addItem(horizontalSpacer);
    108.  
    109. buttonBox = new QDialogButtonBox(layoutWidget);
    110. buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
    111. buttonBox->setOrientation(Qt::Horizontal);
    112. buttonBox->setStandardButtons(QDialogButtonBox::Close);
    113. buttonBox->setCenterButtons(false);
    114.  
    115. horizontalLayout->addWidget(buttonBox);
    116.  
    117.  
    118. verticalLayout_2->addLayout(horizontalLayout);
    119.  
    120. #ifndef QT_NO_SHORTCUT
    121. label->setBuddy(decEdit);
    122. label_2->setBuddy(hexEdit);
    123. label_3->setBuddy(binEdit);
    124. #endif // QT_NO_SHORTCUT
    125. QWidget::setTabOrder(decEdit, hexEdit);
    126. QWidget::setTabOrder(hexEdit, binEdit);
    127.  
    128. retranslateUi(Dialog);
    129. QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), Dialog, SLOT(accept()));
    130.  
    131.  
    132. QIntValidator* decValidator = new QIntValidator(0, 255, decEdit);
    133. decEdit -> setValidator(decValidator);
    134.  
    135. QRegExpValidator* hexValidator = new QRegExpValidator(QRegExp ("[0-9A-Fa-f]{1,2}"), hexEdit);
    136. hexEdit -> setValidator(hexValidator);
    137.  
    138. QRegExpValidator* binValidator = new QRegExpValidator(QRegExp("[01]{1,8}"), binEdit);
    139. binEdit -> setValidator(binValidator);
    140.  
    141.  
    142. QObject::connect(decEdit, SIGNAL(textEdited(QString)), Dialog, SLOT(decChanged(QString)));
    143. QObject::connect(hexEdit, SIGNAL(textChanged(QString)), Dialog, SLOT(hexChanged(QString)));
    144. QObject::connect(binEdit, SIGNAL(textChanged(QString)), Dialog, SLOT(binChanged(QString)));
    145.  
    146. QMetaObject::connectSlotsByName(Dialog);
    147. } // setupUi
    148.  
    149. void retranslateUi(QDialog *Dialog)
    150. {
    151. Dialog->setWindowTitle(QApplication::translate("Dialog", "Byte Converter", 0, QApplication::UnicodeUTF8));
    152. Dialog->setProperty("on_DecEdit_Changed", QVariant(QApplication::translate("Dialog", "0", 0, QApplication::UnicodeUTF8)));
    153. label->setText(QApplication::translate("Dialog", "Dec", 0, QApplication::UnicodeUTF8));
    154. binEdit->setProperty("binProbe", QVariant(QApplication::translate("Dialog", "asfad", 0, QApplication::UnicodeUTF8)));
    155. label_2->setText(QApplication::translate("Dialog", "Hex", 0, QApplication::UnicodeUTF8));
    156. label_3->setText(QApplication::translate("Dialog", "Bin", 0, QApplication::UnicodeUTF8));
    157. } // retranslateUi
    158.  
    159. private slots:
    160. // void decChanged (const QString&);
    161. // void hexChanged (const QString&);
    162. // void binChanged (const QString&);
    163.  
    164. void decChanged (const QString &newValue)
    165. {
    166. bool ok;
    167. int num = newValue.toInt(&ok);
    168. if (ok) {
    169. hexEdit->setText(QString::number(num, 16));
    170. binEdit->setText(QString::number(num, 2));
    171. } else {
    172. hexEdit->setText("0");
    173. binEdit->setText("0");
    174. }
    175. }
    176.  
    177. void hexChanged (const QString &newValue)
    178. {
    179. bool ok;
    180. int num = newValue.toInt(&ok, 16);
    181. if (ok) {
    182. decEdit->setText(QString::number(num, 10));
    183. binEdit->setText(QString::number(num, 2));
    184. } else {
    185. decEdit->setText("");
    186. binEdit->setText("");
    187. }
    188. }
    189.  
    190. void binChanged (const QString &newValue)
    191. {
    192. bool ok;
    193. int num = newValue.toInt(&ok, 2);
    194. if (ok) {
    195. decEdit->setText(QString::number(num, 10));
    196. hexEdit->setText(QString::number(num, 16));
    197. } else {
    198. decEdit->setText("");
    199. hexEdit->setText("");
    200. }
    201. }
    202.  
    203.  
    204. /*void on_DecEdit_Changed ( const QString& newValue )
    205.   {
    206.   bool ok;
    207.   int num = newValue.toInt ( &ok );
    208.   if ( ok ) {
    209.   QLineEdit hexEdit ( QString::number ( num, 16 ) );
    210.   QLineEdit binChanged ( QString::number ( num, 2 ) );
    211.   } else {
    212.   QLineEdit hexChanged ( "" );
    213.   QLineEdit binChanged ( "" );
    214.   }
    215.   }*/
    216. };
    217.  
    218. namespace Ui {
    219. class Dialog: public Ui_Dialog {};
    220. } // namespace Ui
    221.  
    222. QT_END_NAMESPACE
    223.  
    224. #endif // UI_BYTECONVERTERDIALOG_H
    To copy to clipboard, switch view to plain text mode 

    dialog.cpp:
    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_byteconverterdialog.h"
    3.  
    4. Dialog::Dialog(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::Dialog)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. Dialog::~Dialog()
    12. {
    13. delete ui;
    14. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "dialog.h"
    3. #include "ui_byteconverterdialog.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. QDialog dlg;
    9. Ui_Dialog ui;
    10. ui.setupUi(&dlg);
    11. dlg.setAttribute(Qt::WA_QuitOnClose);
    12. dlg.show();
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    Please help.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: "No such slot..."

    My guess is you added the "Q_OBJECT" macro to an existing file and you didn't rerun qmake afterwards.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: "No such slot..."

    My guess is more fundamental: The declaration of those slots in the Dialog class are commented out and there is no implementation of them at all. Since the parent class (QDialog) also has no slots of those names that you inherit you get the warnings when the Designer Ui code tries to connect.

  4. #4
    Join Date
    May 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: "No such slot..."

    I thought i know enough to start qt, but i was wrong. But i want to finish this program. I've uncomment slots and tried with moving declaration to dialog.h and dialog.cpp. Now the problem is undefined reference to Dialog::decChanged(QString const&) and others slots in moc_dialog.cpp. Please give me instructions what to do and i will be back much more experienced...

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: "No such slot..."

    Did you rerun qmake?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    May 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: "No such slot..."

    Of course i did. Several times.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: "No such slot..."

    Is decChanged() a slot or a signal? How is it declared in the class?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8

    Default Re: "No such slot..."

    Hi,

    I'm new to Qt and C++ so I'm asking questions about this problem to learn and test my knowledge. Unfortunately I don't have the "for sure" answer.

    I'm not familiar with the book you are using. Does it have you modify the ui_... .h file?

    I would try uncommenting the slot declarations in the dialog.h file, then add the slot functions to the dialog.cpp file e.g.
    Qt Code:
    1. Dialog::void decChanged (const QString &newValue)
    2. {
    3. bool ok;
    4. int num = newValue.toInt(&ok);
    5. if (ok) {
    6. hexEdit->setText(QString::number(num, 16));
    7. binEdit->setText(QString::number(num, 2));
    8. } else {
    9. hexEdit->setText("0");
    10. binEdit->setText("0");
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 5
    Last Post: 24th May 2010, 21:20
  2. debugging "signal does not reach slot" in a template class
    By Daniel Dekkers in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2010, 16:03
  3. Replies: 1
    Last Post: 5th January 2010, 13:34
  4. Replies: 1
    Last Post: 23rd August 2008, 22:09
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.