I've written this piece of the code A QWidget which has a QSlider and QLineEdit They are connected to each other with their value. there are two new SLOTs which will convert their values and will call other widget to change its value. until here, everything works perfectly.
But I have added a new SIGNAL, which must be emmited when the value reaches 80. And after that the instance of the QAPPlication must be closed. This part doesn't work. Why?
#include "windows.h"
#include <QSlider>
#include <QLineEdit>
#include <QGridLayout>
#include <QApplication>
windows::windows(QWidget *parent) :
QWidget(parent)
{
sld=new QSlider(Qt::Horizontal,this);
sld->setRange(0,100);
led= new QLineEdit(this);
QGridLayout *grid=new QGridLayout(this);
grid->addWidget(sld,0,0);
grid->addWidget(led,0,1);
connect(led,SIGNAL(textEdited(QString)),this,SLOT(setSlider(QString)));
connect(sld,SIGNAL(valueChanged(int)),this,SLOT(setLed(int)));
connect(sld,SIGNAL(reached()),QApplication::instance(),SLOT(quit()));
}
void windows::setSlider(QString value)
{
int intValue=value.toInt();
sld->setValue(intValue);
if(intValue>80)
emit reached();
}
void windows::setLed(int value)
{
QString Qvalue=QString::number(value);
led->setText(Qvalue);
if(value>80)
emit reached();
}