Results 1 to 4 of 4

Thread: Object::connect: No such slot ThreadDialog::closeEvent(event)

  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Object::connect: No such slot ThreadDialog::closeEvent(event)

    Dear Sir!
    In this code application is running but give this messge...
    Object::connect: No such slot ThreadDialog::closeEvent(event)
    Qt Code:
    1. /*t.h file*/
    2. #ifndef T_H
    3. #define T_H
    4. #include <QtGui>
    5. class MyThread : public QThread
    6. {
    7. Q_OBJECT
    8. public:
    9. MyThread(QObject *parent=0);
    10. void setMessage(const QString &message);
    11. void stop();
    12. protected:
    13. void run();
    14. private:
    15. QString msg;
    16. volatile bool stopped;
    17. };
    18.  
    19. class ThreadDialog : public QDialog
    20. {
    21. Q_OBJECT
    22. public:
    23. ThreadDialog(QApplication *app,QWidget *parent = 0);
    24. protected:
    25. void closeEvent(QCloseEvent *event);
    26. private slots:
    27. void startOrStopThreadA();
    28. void startOrStopThreadB();
    29. private:
    30. MyThread threadA;
    31. MyThread threadB;
    32. QPushButton *threadAButton;
    33. QPushButton *threadBButton;
    34. QPushButton *quitButton;
    35. };
    36. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /*t.cpp*/
    2. #include <iostream.h>
    3. #include <t.h>
    4. #include <QString>
    5. int i=0;
    6.  
    7. MyThread::MyThread(QObject *parent)
    8. : QThread(parent)
    9. {
    10. stopped = false;
    11. }
    12.  
    13. void MyThread::run()
    14. {
    15.  
    16.  
    17. while (!stopped)
    18. {
    19. cerr << qPrintable(msg)<< endl;
    20. //msleep(500);
    21. }
    22. stopped=false;
    23. }
    24.  
    25.  
    26. void MyThread::stop()
    27. {
    28. stopped = true;
    29. }
    30. void MyThread::setMessage(const QString &message)
    31. {
    32. msg=message;
    33. //run();
    34. }
    35.  
    36. ThreadDialog::ThreadDialog(QApplication *app,QWidget *parent)
    37. : QDialog(parent)
    38. {
    39. threadA.setMessage("Anurag");
    40. threadB.setMessage("Sonu");
    41. threadAButton = new QPushButton(tr("Start A"),this);
    42. threadBButton = new QPushButton(tr("Start B"),this);
    43. quitButton = new QPushButton(tr("Quit"),this);
    44. QHBoxLayout *layout=new QHBoxLayout;
    45. layout->addWidget(threadAButton);
    46. layout->addWidget(threadBButton);
    47. layout->addWidget(quitButton);
    48. QHBoxLayout *mainLayout=new QHBoxLayout;
    49. mainLayout->addLayout(layout);
    50. setLayout(mainLayout);
    51. quitButton->setDefault(true);
    52.  
    53. connect(threadAButton, SIGNAL(clicked()), this, SLOT(startOrStopThreadA()));
    54. connect(threadBButton, SIGNAL(clicked()), this, SLOT(startOrStopThreadB()));
    55. QCloseEvent *event=new QCloseEvent();
    56. connect(quitButton, SIGNAL(clicked()), this, SLOT(closeEvent(event)));
    57. }
    58.  
    59. void ThreadDialog::startOrStopThreadA()
    60. {
    61. if (threadA.isRunning()) {
    62. threadA.stop();
    63. threadAButton->setText(tr("Start A"));
    64. } else {
    65. threadA.start();
    66. threadAButton->setText(tr("Stop A"));
    67. }
    68. }
    69. void ThreadDialog::startOrStopThreadB()
    70. {
    71. if (threadB.isRunning()) {
    72. threadB.stop();
    73. threadBButton->setText(tr("Start B"));
    74. } else {
    75. threadB.start();
    76. threadBButton->setText(tr("Stop B"));
    77. }
    78. }
    79.  
    80. void ThreadDialog::closeEvent(QCloseEvent *event)
    81. {
    82. threadA.stop();
    83. threadB.stop();
    84. threadA.wait();
    85. threadB.wait();
    86. event->accept();
    87. }
    88.  
    89. int main(int argc, char **argv)
    90. {
    91. QApplication app(argc,argv);
    92. ThreadDialog t(&app);
    93. t.resize(300,200);
    94. t.show();
    95. return app.exec();
    96. }
    To copy to clipboard, switch view to plain text mode 
    plz give some proper suggestions.
    with regards!
    Last edited by wysota; 23rd September 2007 at 20:27. Reason: missing [code] tags
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Object::connect: No such slot ThreadDialog::closeEvent(event)

    As it says, QWidget::closeEvent() is not a slot. Furthermore, signals and slots don't work that way. You can't add variables to connect statement.
    Qt Code:
    1. connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    Recommended reading: signals and slots
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Object::connect: No such slot ThreadDialog::closeEvent(event)

    Quote Originally Posted by jpn View Post
    As it says, QWidget::closeEvent() is not a slot. Furthermore, signals and slots don't work that way. You can't add variables to connect statement.
    Qt Code:
    1. connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    Recommended reading: signals and slots
    Dear Sir!
    I have used close slot before viewing this post. But I couldn't think this QWidget::closeEvent() is a function however I have seen this function earlier; So I am facing trouble.
    Thanks!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Object::connect: No such slot ThreadDialog::closeEvent(event)

    Don't guess and seem to remember which one is slot and which one is not. It is all clearly and well documented in the Qt reference documentation. I keep Qt Assistant always open while writing anything related to Qt. I suggest you do the same.
    J-P Nurmi

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Signal / Slot with specific argument and threads
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 14th September 2007, 23:43
  3. Problem with slot
    By beerkg in forum Qt Programming
    Replies: 29
    Last Post: 3rd April 2007, 19:54
  4. Example HowTo create custom view
    By dexjam in forum Newbie
    Replies: 6
    Last Post: 12th July 2006, 11:06
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.