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)
Code:
/*t.h file*/
#ifndef T_H
#define T_H
#include <QtGui>
{
Q_OBJECT
public:
void setMessage
(const QString &message
);
void stop();
protected:
void run();
private:
volatile bool stopped;
};
class ThreadDialog
: public QDialog{
Q_OBJECT
public:
protected:
private slots:
void startOrStopThreadA();
void startOrStopThreadB();
private:
MyThread threadA;
MyThread threadB;
};
#endif
Code:
/*t.cpp*/
#include <iostream.h>
#include <t.h>
#include <QString>
int i=0;
MyThread
::MyThread(QObject *parent
){
stopped = false;
}
void MyThread::run()
{
while (!stopped)
{
cerr << qPrintable(msg)<< endl;
//msleep(500);
}
stopped=false;
}
void MyThread::stop()
{
stopped = true;
}
void MyThread
::setMessage(const QString &message
) {
msg=message;
//run();
}
{
threadA.setMessage("Anurag");
threadB.setMessage("Sonu");
layout->addWidget(threadAButton);
layout->addWidget(threadBButton);
layout->addWidget(quitButton);
mainLayout->addLayout(layout);
setLayout(mainLayout);
quitButton->setDefault(true);
connect(threadAButton, SIGNAL(clicked()), this, SLOT(startOrStopThreadA()));
connect(threadBButton, SIGNAL(clicked()), this, SLOT(startOrStopThreadB()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(closeEvent(event)));
}
void ThreadDialog::startOrStopThreadA()
{
if (threadA.isRunning()) {
threadA.stop();
threadAButton->setText(tr("Start A"));
} else {
threadA.start();
threadAButton->setText(tr("Stop A"));
}
}
void ThreadDialog::startOrStopThreadB()
{
if (threadB.isRunning()) {
threadB.stop();
threadBButton->setText(tr("Start B"));
} else {
threadB.start();
threadBButton->setText(tr("Stop B"));
}
}
{
threadA.stop();
threadB.stop();
threadA.wait();
threadB.wait();
event->accept();
}
int main(int argc, char **argv)
{
ThreadDialog t(&app);
t.resize(300,200);
t.show();
return app.exec();
}
plz give some proper suggestions.
with regards!
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.
Code:
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
Recommended reading: signals and slots
Re: Object::connect: No such slot ThreadDialog::closeEvent(event)
Quote:
Originally Posted by
jpn
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.
Code:
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
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!
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. ;)