Results 1 to 4 of 4

Thread: Why I see: Object::connect: No such slot QDialog::showName(QString) in

  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Why I see: Object::connect: No such slot QDialog::showName(QString) in

    Hi,

    Why I see: Object::connect: No such slot QDialog::showName(QString) in ../DialogByButton/mainwindow.cpp:29

    DialogByButton.pro
    Qt Code:
    1. SOURCES += \
    2. main.cpp \
    3. mainwindow.cpp \
    4. dialog.cpp
    5.  
    6. HEADERS += \
    7. mainwindow.h \
    8. dialog.h
    To copy to clipboard, switch view to plain text mode 

    dialog.h
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5. #include <QtGui>
    6.  
    7. class Dialog : public QDialog
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit Dialog(QWidget *parent = 0);
    12.  
    13. signals:
    14.  
    15. public slots:
    16. void showName(QString name);
    17.  
    18. private:
    19. QLabel *lblName;
    20. };
    21.  
    22. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    dialog.cpp
    Qt Code:
    1. #include "dialog.h"
    2.  
    3. Dialog::Dialog(QWidget *parent) :
    4. QDialog(parent)
    5. {
    6. // Controls
    7. lblName = new QLabel(tr("Hahah"));
    8.  
    9. // Layouts
    10. QHBoxLayout* mainLayout = new QHBoxLayout(this);
    11. mainLayout->addWidget(lblName);
    12.  
    13. // Set Layout
    14. this->setLayout(mainLayout);
    15. }
    16.  
    17. void Dialog::showName(QString name) {
    18. //lblName->setText(name);
    19. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QtGui>
    6.  
    7. class MainWindow : public QMainWindow
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit MainWindow(QWidget *parent = 0);
    12.  
    13. signals:
    14. void sendName(QString name);
    15.  
    16. private slots:
    17. void callDialog();
    18.  
    19. private:
    20. QLineEdit *leName;
    21. };
    22.  
    23. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "dialog.h"
    3. #include <QWidget>
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent)
    7. {
    8. // Controls
    9. QLabel *lblName = new QLabel(tr("Enter your name:"));
    10. leName = new QLineEdit;
    11. QPushButton *btnCallDialog = new QPushButton(tr("Call Dialog"));
    12.  
    13. // Layout
    14. QGridLayout *mainLayout = new QGridLayout;
    15. mainLayout->addWidget(lblName, 0, 0);
    16. mainLayout->addWidget(leName, 0, 1);
    17. mainLayout->addWidget(btnCallDialog, 1, 0, 1, 2);
    18.  
    19. // Set center widget
    20. QWidget *widget = new QWidget;
    21. widget->setLayout(mainLayout);
    22. this->setCentralWidget(widget);
    23.  
    24. connect(btnCallDialog, SIGNAL(clicked()), this, SLOT(callDialog()));
    25. }
    26.  
    27. void MainWindow::callDialog() {
    28. QDialog *dialog = new QDialog(this);
    29. connect(this, SIGNAL(sendName(QString)), dialog, SLOT(showName(QString)));
    30. emit sendName(leName->text());
    31. dialog->show();
    32. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main (int argc, char *argv[]) {
    5. QApplication app(argc, argv);
    6.  
    7. MainWindow window;
    8. window.show();
    9.  
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Thank you!

  2. #2
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: Why I see: Object::connect: No such slot QDialog::showName(QString) in

    I solved this problem.

    I write instead:
    Qt Code:
    1. void MainWindow::callDialog() {
    2. QDialog *dialog = new QDialog(this);
    3. connect(this, SIGNAL(sendName(QString)), dialog, SLOT(showName(QString)));
    4. emit sendName(leName->text());
    5. dialog->show();
    6. }
    To copy to clipboard, switch view to plain text mode 

    This code:
    Qt Code:
    1. void MainWindow::callDialog() {
    2. Dialog dialog;
    3. connect(this, SIGNAL(sendName(QString)), &dialog, SLOT(showName(QString)));
    4. emit sendName(leName->text());
    5. dialog.exec();
    6. }}
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Why I see: Object::connect: No such slot QDialog::showName(QString) in

    Obviously QDialog does not have a slot that you declared in a subclass of QDialog

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    8Observer8 (15th October 2013)

  5. #4
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: Why I see: Object::connect: No such slot QDialog::showName(QString) in

    Thank you

Similar Threads

  1. Object::connect: No such slot
    By kango in forum Newbie
    Replies: 8
    Last Post: 20th February 2013, 10:00
  2. Replies: 4
    Last Post: 28th October 2011, 05:09
  3. Anoying problem, Object::connect: No such slot
    By Aslund in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2011, 08:09
  4. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  5. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02

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.